Slide 1

Slide 1 text

@markbates

Slide 2

Slide 2 text

hire me* (for rent, not sale)

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

KODIO13 www.metacasts.tv

Slide 7

Slide 7 text

AngularJS vs. Ember vs. Backbone.js

Slide 8

Slide 8 text

Knockout.js

Slide 9

Slide 9 text

philosophies

Slide 10

Slide 10 text

Backbone.js “minimal set of data-structure and view primitives for building web application with JavaScript”

Slide 11

Slide 11 text

Backbone.js do what you want, however you want to do it (we won’t tell anyone)

Slide 12

Slide 12 text

Ember “framework for creating ambitious web applications”

Slide 13

Slide 13 text

Ember convention over configuration

Slide 14

Slide 14 text

AngularJS “Toolset for building the framework most suited to your application development”

Slide 15

Slide 15 text

AngularJS plain old JavaScript

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

Round 1

Slide 20

Slide 20 text

weight

Slide 21

Slide 21 text

“production” versions (minified) w/ required dependencies

Slide 22

Slide 22 text

AngularJS Ember Backbone.js base 81kb 235kb 6.4kb templating language built-in 73kb (handlebars) ?? data adapter built-in 210kb (ember-data) 32kb (jQuery) support N/A 32kb (jQuery) 17kb (json2.js) 4.9kb (underscore.js) 81kb 550kb 60.3kb

Slide 23

Slide 23 text

Round 2

Slide 24

Slide 24 text

“basic” models

Slide 25

Slide 25 text

Backbone.js class  App.Beer  extends  Backbone.Model       class  App.Beers  extends  Backbone.Collection   !  model:  Beer

Slide 26

Slide 26 text

Ember App.Beer  =  DS.Model.extend      title:  DS.attr("string")      abv:  DS.attr("number")      country_id:  DS.attr("number")      brewery_id:  DS.attr("number")      brewery:  DS.belongsTo("App.Brewery")      country:  DS.belongsTo("App.Country")

Slide 27

Slide 27 text

AngularJS App.Beer  =  {}

Slide 28

Slide 28 text

“remote” models

Slide 29

Slide 29 text

Backbone.js class  App.Beer  extends  Backbone.Model      urlRoot:  "/api/v1/beers"         class  App.Beers  extends  Backbone.Collection          url:  -­‐>          if  @brewery_id?              return  "/api/v1/breweries/#{@brewery_id}/beers"          else              return  "/api/v1/beers"          model:  Beer

Slide 30

Slide 30 text

Ember App.Beer  =  DS.Model.extend      title:  DS.attr("string")      abv:  DS.attr("number")      country_id:  DS.attr("number")      brewery_id:  DS.attr("number")      brewery:  DS.belongsTo("App.Brewery")      country:  DS.belongsTo("App.Country")

Slide 31

Slide 31 text

Ember DS.RESTAdapter.reopen      namespace:  'api/v1'       App.Store  =  DS.Store.extend      revision:  11      adapter:  DS.RESTAdapter.create()

Slide 32

Slide 32 text

AngularJS App.factory  "Beer",  ($resource)  -­‐>      return  $resource  "/api/v1/beers/:id",                                        {id:  "@id"},                                        {update:  {method:  "PUT"}}

Slide 33

Slide 33 text

Round 3

Slide 34

Slide 34 text

routers

Slide 35

Slide 35 text

Backbone.js @Router  =  Backbone.Router.extend          initialize:  -­‐>          @countries  =  new  Countries()          routes:          "breweries/:brewery_id":  "brewery"          "breweries/:brewery_id/edit":  "breweryEdit"          brewery:  (brewery_id)  -­‐>          @changeView(new  BreweryView(collection:  @countries,  model:  new  Brewery(id:  brewery_id)))          breweryEdit:  (brewery_id)  -­‐>          @changeView(new  BreweryEditView(collection:  @countries,  model:  new  Brewery(id:  brewery_id)))          changeView:  (view)  =>          @currentView?.remove()          @currentView  =  view          $("#outlet").html(@currentView.el)

Slide 36

Slide 36 text

Ember App.Router.map  -­‐>      @resource  "brewery",  {path:  "brewery/:brewery_id"}

Slide 37

Slide 37 text

Ember App.BreweryRoute  =  Ember.Route.extend      model:  (params)-­‐>          App.Brewery.find(params.brewery_id)

Slide 38

Slide 38 text

AngularJS App.config  ($routeProvider)  -­‐>          $routeProvider          .when("/breweries/:id",  {              templateUrl:  "/assets/brewery.html",              controller:  "BreweryController"          })          .when("/breweries/:id/edit",  {              templateUrl:  "/assets/edit_brewery.html",              controller:  "EditBreweryController"          })

Slide 39

Slide 39 text

Round 4

Slide 40

Slide 40 text

controllers/views

Slide 41

Slide 41 text

Backbone.js class  @BreweryEditView  extends  Backbone.View          template:  "brewery_edit"          events:          "click  #save-­‐button":  "saveClicked"          "keypress  #brewery-­‐title":  "titleEdited"          initialize:  -­‐>          super          @countriesView  =  new  CountriesView(collection:  @collection)          @$el.html(@countriesView.el)          @model.on  "change",  @render          @model.fetch()          render:  =>          @$("#country-­‐outlet").html(@renderTemplate())          return  @    saveClicked:  (e)  =>          e?.preventDefault()          attrs  =              title:  @$("#brewery-­‐title").val()              synonyms:  @$("#brewery-­‐synonyms").val()              address:  @$("#brewery-­‐address").val()          @model.save  attrs,              success:  (model,  response,  options)  =>                  App.navigate("/breweries/#{@model.id}",  trigger:  true)              error:  (model,  xhr,  options)  -­‐>                  errors  =  []                  for  key,  value  of  xhr.responseJSON.errors                      errors.push  "#{key}:  #{value.join(",  ")}"                  alert  errors.join("\n")          titleEdited:  (e)  =>          title  =  @$("#brewery-­‐title").val()          @$("h2").text(title)   !    #  further  code  omitted

Slide 42

Slide 42 text

Ember App.BreweryController  =  Ember.ObjectController.extend        save:  -­‐>          @store.commit()          #  further  code  omitted

Slide 43

Slide 43 text

AngularJS @EditBreweryController  =  ($scope,  $routeParams,  $location,  Brewery)  -­‐>          $scope.brewery  =  Brewery.get(id:  $routeParams.id)          $scope.save  =  -­‐>          success  =  -­‐>              $location.path("/breweries/#{$routeParams.id}")              $scope.errors  =  null          failure  =  (object)-­‐>              $scope.errors  =  object.data.errors          $scope.brewery.$update  {},  success,  failure

Slide 44

Slide 44 text

Round 5

Slide 45

Slide 45 text

templates

Slide 46

Slide 46 text

Backbone.js

<%=  @model.displayName()  %>

               
         Title          
                       
     
         
         Synonyms          
                       
     
         
         Address          
             <%=  @model.get("address")  %>          
     
         Save      Cancel      

Slide 47

Slide 47 text

Backbone.js

<%=  @model.displayName()  %>

               
         Title          
                       
     
         
         Synonyms          
                       
     
         
         Address          
             <%=  @model.get("address")  %>          
     
         Save      Cancel                  

Slide 48

Slide 48 text

Backbone.js

<%=  @model.displayName()  %>

               
         Title          
                       
     
         
         Synonyms          
                       
     
         
         Address          
              <%=  @model.get("address")   %>          
     
         Save      Cancel                   <%=  @model.get("address")   %>

Slide 49

Slide 49 text

     

{{displayName}}

     

         {{cityState}}          {{#linkTo  "country"  country}}              {{country.title}}          {{/linkTo}}      

     {{#if  isEditing}}                            
                 Title                  
                     {{view  Ember.TextField  valueBinding="title"  class='input-­‐xxlarge'}}                  
             
                 
                 Synonyms                  
                     {{view  Ember.TextField  valueBinding="synonyms"  class='input-­‐xxlarge'}}                  
             
                 
                 Synonyms                  
                     {{view  Ember.TextArea  valueBinding="address"  class='input-­‐xxlarge'}}                  
             
                 Save                    {{  else  }}          {{  partial  "brewery/show"  }}      {{/if}}  
Ember

Slide 50

Slide 50 text

     

{{displayName}}

     

         {{cityState}}          {{#linkTo  "country"  country}}              {{country.title}}          {{/linkTo}}      

     {{#if  isEditing}}                            
                 Title                  
                      {{view  Ember.TextField  valueBinding="title"  class='input-­‐xxlarge'}}                  
             
                 
                 Synonyms                  
                     {{view  Ember.TextField  valueBinding="synonyms"  class='input-­‐xxlarge'}}                  
             
                 
                 Synonyms                  
                     {{view  Ember.TextArea  valueBinding="address"  class='input-­‐xxlarge'}}                  
             
                 Save                    {{  else  }}          {{  partial  "brewery/show"  }}      {{/if}}  
Ember                     {{view  Ember.TextField  valueBinding="title"  class='input-­‐xxlarge'}}

Slide 51

Slide 51 text

     

{{displayName}}

     

         {{cityState}}          {{#linkTo  "country"  country}}              {{country.title}}          {{/linkTo}}      

     {{#if  isEditing}}                            
                 Title                  
                     {{view  Ember.TextField  valueBinding="title"  class='input-­‐xxlarge'}}                  
             
                 
                 Synonyms                  
                     {{view  Ember.TextField  valueBinding="synonyms"  class='input-­‐xxlarge'}}                  
             
                 
                 Synonyms                  
                     {{view  Ember.TextArea  valueBinding="address"  class='input-­‐xxlarge'}}                  
             
                  Save                    {{  else  }}          {{  partial  "brewery/show"  }}      {{/if}}  
Ember             Save

Slide 52

Slide 52 text

     

{{brewery.title}}

     
     
         Title          
                       
     
         
         Synonyms          
                       
     
         
         Address          
                       
     
         Save       AngularJS

Slide 53

Slide 53 text

AngularJS      

{{brewery.title}}

     
     
         Title          
                       
     
         
         Synonyms          
                       
     
         
         Address          
                       
     
         Save                  

Slide 54

Slide 54 text

     

{{brewery.title}}

     
     
         Title          
                       
     
         
         Synonyms          
                       
     
         
         Address          
                       
     
         Save       AngularJS    Save

Slide 55

Slide 55 text

Round 6

Slide 56

Slide 56 text

pros/cons

Slide 57

Slide 57 text

Backbone.js • Too simple • Not opinionated enough • “Memory” management • Unstructured • Spaghetti code • Lightweight • Not opinionated • Simple • Easy to read source • “widget” development Pros Cons

Slide 58

Slide 58 text

Ember • Too complex • Overly opinionated • Heavyweight • ember-data - not production ready • API always in flux • Buggy • Little to no mind-share outside of Rails • Difficult to read source code • Structured • Highly opinionated • “less” code • “large” apps Pros Cons

Slide 59

Slide 59 text

AngularJS • Difficult to read source code • jQuery plugins require custom directives • Large apps requiring self-imposed structure • Lightly structured • Lightly opinionated • “less” code • Plain JavaScript • Simple/Powerful • Easy to test • Lightweight • small, medium, or large apps Pros Cons

Slide 60

Slide 60 text

Summary

Slide 61

Slide 61 text

think before you choose

Slide 62

Slide 62 text

don’t cargo cult

Slide 63

Slide 63 text

don’t use Backbone.js!

Slide 64

Slide 64 text

play with them all

Slide 65

Slide 65 text

watch the metacasts.tv episodes on them ;)

Slide 66

Slide 66 text

@markbates http://www.metacasts.tv