Slide 1

Slide 1 text

Mind the Front-End Gap: Navigating the Path from

Slide 2

Slide 2 text

cball_ Chris Ball Ǧ

Slide 3

Slide 3 text

This talk is NOT… cball_

Slide 4

Slide 4 text

Not to debate front-end frameworks. cball_

Slide 5

Slide 5 text

Not to debate server-side alternatives. cball_

Slide 6

Slide 6 text

Not to convince Sam Phippen to use SPA's. cball_

Slide 7

Slide 7 text

Here's a quick pitch. (maybe this is you?) cball_

Slide 8

Slide 8 text

❤ cball_

Slide 9

Slide 9 text

conventions. ❤ cball_

Slide 10

Slide 10 text

conventions. ❤ cball_

Slide 11

Slide 11 text

Therefore cball_

Slide 12

Slide 12 text

❤ cball_

Slide 13

Slide 13 text

Conventions give us superpowers. http://realitypod.com/wp-content/uploads/2011/03/super-strength.jpg

Slide 14

Slide 14 text

Productivity++ cball_

Slide 15

Slide 15 text

Great Tooling (you're used to this) rails serve rails test rails generate rails new bundle gem cball_

Slide 16

Slide 16 text

Great Tooling ember-cli will feel familiar! ember serve ember test ember generate ember new ember addon cball_

Slide 17

Slide 17 text

ember s ember t ember g ember new ember addon cball_ Great Tooling ember-cli will feel familiar!

Slide 18

Slide 18 text

Much of what you know has direct equivalents. cball_

Slide 19

Slide 19 text

cball_ Router Model View ActiveRecord Gems Controller Router Model Template Ember Data Addons Route

Slide 20

Slide 20 text

cball_ link_to yield things.each do |t| helpers pluralize link-to outlet each things as |t| helpers pluralize

Slide 21

Slide 21 text

The Ember Inspector

Slide 22

Slide 22 text

Easily handle complicated async javascript in tests. cball_

Slide 23

Slide 23 text

visit('/'); click('.button'); fillIn('.name', 'Chris'); click('.another'); andThen(()=> { let something = $('h2').text(); assert.equal(something, 'yay'); }); cball_

Slide 24

Slide 24 text

Get that “$@#% that’s awesome!” moment you got learning Rails. cball_

Slide 25

Slide 25 text

Necessary mindset adjustments. cball_

Slide 26

Slide 26 text

Request + Response. cball_ ɂ Ȑ

Slide 27

Slide 27 text

All the things are rebuilt on every request. cball_

Slide 28

Slide 28 text

Keep memory in mind. cball_

Slide 29

Slide 29 text

Great browser-provided tools cball_

Slide 30

Slide 30 text

Controllers fetch data. cball_ class SongController def show @song = Song.find(params[:id]) end end

Slide 31

Slide 31 text

Routes fetch data. cball_ // app/routes/song.js export default Ember.Route.extend({ model(params) { return this.store.findRecord('song', params.id); } });

Slide 32

Slide 32 text

Routes fetch data. cball_ {{! app/templates/song.hbs }} My amazing song is {{model.name}}

Slide 33

Slide 33 text

Rendering is slow. Does this look familiar? Completed 200 OK in 1749ms (Views: 1725.7ms | ActiveRecord: 23.3ms) cball_

Slide 34

Slide 34 text

Caching is the only way to speed it up. cball_

Slide 35

Slide 35 text

Rendering is fast! New rendering engine based on lessons learned from React.

Slide 36

Slide 36 text

JavaScript is something to sprinkle in. cball_

Slide 37

Slide 37 text

On JavaScript heavy pages, what happens if user refreshes?

Slide 38

Slide 38 text

They start over.

Slide 39

Slide 39 text

Focus on URLs. Ember Router maps URL to application state. Helps avoid the refresh issue. cball_

Slide 40

Slide 40 text

Rails manages assets. cball_ css js images

Slide 41

Slide 41 text

Asset Pipeline = Ember will handle assets during the build process before deploying. cball_

Slide 42

Slide 42 text

Nest related API resource URLs. cball_

Slide 43

Slide 43 text

/users/23/songs/11 cball_

Slide 44

Slide 44 text

/users/:user_id/songs/:song_id cball_ (shouldn't have to pass this to fetch single song)

Slide 45

Slide 45 text

Keep resource API urls as flat as possible. cball_

Slide 46

Slide 46 text

Run jQuery hooks on page load. cball_

Slide 47

Slide 47 text

Components. cball_

Slide 48

Slide 48 text

cball_ {{#each model as |post|}} {{#blog-post title=post.title}} {{post.body}} {{/blog-post}} {{/each}} Components.

Slide 49

Slide 49 text

cball_

{{title}}

{{yield}}

Edit title: {{input type="text" value=title}}

Components.

Slide 50

Slide 50 text

Use jQuery code only in a component's didInsertElement hook. cball_

Slide 51

Slide 51 text

Always, always add corresponding willDestroyElement hook. cball_

Slide 52

Slide 52 text

If you use Bootstrap, don't blindly include their JavaScript. cball_

Slide 53

Slide 53 text

cball_ "I JavaScript!"

Slide 54

Slide 54 text

It's a little better with CoffeeScript. cball_

Slide 55

Slide 55 text

Learn to JavaScript. cball_

Slide 56

Slide 56 text

Don't use CoffeeScript. cball_

Slide 57

Slide 57 text

ES6 support out of the box Eliminates the need for CoffeeScript and adds additional features. http:/babeljs.io

Slide 58

Slide 58 text

It's not enjoyable because you've fought with it. cball_

Slide 59

Slide 59 text

Lean on Ember's conventions instead of fighting. cball_

Slide 60

Slide 60 text

Use accepts_nested_attributes_for. cball_

Slide 61

Slide 61 text

Forget about accepts_nested_attributes_for. cball_

Slide 62

Slide 62 text

Make an ajax request that returns JavaScript to update a snippet in a view. cball_

Slide 63

Slide 63 text

js.erb cball_

Slide 64

Slide 64 text

cball_ Templates are bound, so values update automatically.

Slide 65

Slide 65 text

Parts of mindset to keep? cball_

Slide 66

Slide 66 text

You'd be surprised at how many concepts still apply. cball_

Slide 67

Slide 67 text

cball_ Small methods Collaborator objects SRP things hard = doing wrong TDD generators Acceptance tests Unit tests addons = gems blocks, yield CRUD Refactoring Brain ENV config reopen class DDAU = pass messages

Slide 68

Slide 68 text

Too long, didn't listen. cball_ more code!

Slide 69

Slide 69 text

cball_

Slide 70

Slide 70 text

cball_

Slide 71

Slide 71 text

cball_

Slide 72

Slide 72 text

cball_

Slide 73

Slide 73 text

cball_

Slide 74

Slide 74 text

cball_

Slide 75

Slide 75 text

cball_

Slide 76

Slide 76 text

cball_

Slide 77

Slide 77 text

What might change in your daily workflow? cball_

Slide 78

Slide 78 text

UI first. API after. cball_

Slide 79

Slide 79 text

cball_

Slide 80

Slide 80 text

Development cball_

Slide 81

Slide 81 text

2 separate repositories. cball_

Slide 82

Slide 82 text

Run both Rails server and Ember server for your app. cball_

Slide 83

Slide 83 text

Continuous Integration cball_

Slide 84

Slide 84 text

You'll be running test suites for 2 apps. cball_

Slide 85

Slide 85 text

Deployment cball_

Slide 86

Slide 86 text

cball_ Heroku ember-cli buildpack - API_URL will set nginx proxy - Requires 2 heroku apps https://github.com/tonycoco/heroku-buildpack-ember-cli

Slide 87

Slide 87 text

cball_ ember-cli-deploy By default, Rails serves index.html from Redis, assets from S3. http://ember-cli.github.io/ember-cli-deploy

Slide 88

Slide 88 text

cball_ capistrano Can be set to deploy front-end and back-end separately. http://capistranorb.com

Slide 89

Slide 89 text

Final thoughts cball_

Slide 90

Slide 90 text

Ember is a brave, new world that's actually familiar. cball_

Slide 91

Slide 91 text

Keep using Rails for a great API and for what makes your app special. cball_

Slide 92

Slide 92 text

Start enjoying front-end development. cball_

Slide 93

Slide 93 text

cball_ ❤

Slide 94

Slide 94 text

cball_ https://thisthatandtheotherthang.wordpress.com/tag/fun-facts/ http://www.amazon.com/Matryoshka-Madness-13001-Ninja/dp/B003EED2LS Image Credits http://www.carbonated.tv/lifestyle/6-funny-dog-faces-to-get-your-day-started http://www.flaticon.com/free-icon/woman-head-side-silhouette_40809

Slide 95

Slide 95 text

cball_ Thanks!