SlideShare ist ein Scribd-Unternehmen logo
1 von 60
Downloaden Sie, um offline zu lesen
Philip Poots
     @pootsbook

     Ruby Developer

     Audacio.us


3

18

3
va Sc ri pt
Ja
Structure
State
Speed
Structure Framework
State Application
Speed Javascript
Structure Framework
State Application
Speed Javascript
$.getJSON("http://example.com/?
feed=json&jsonp=?", function(data){
    $('#content').html("<a href=""
+ data[0].permalink + "">" +
data[0].title + "</a>");
    $('#Date').html(data[0].date);
    $
('#Excerpt').html(data[0].excerpt);
    $('#Excerpt').after("<a href=
"" + data[0].permalink + ""
class="more">read on &raquo;</
a>");
  });
STRUCTURE   MVC Model View Controller
            Pattern
            —1979
            Architecture
            —Separate domain logic & UI
            Server-Side MVC
            —Ruby on Rails
STRUCTURE   MVC on Server
STRUCTURE   MVC on Client
STRUCTURE   Backbone Model
 window.Todo = Backbone.Model.extend({
      defaults: {
         done: false
      },
 
      toggle: function() {
         this.save(
   
 
 
 {done: !this.get("done")}
         );
      }
    });
STRUCTURE   Backbone Model
 window.Todo = Backbone.Model.extend({
      defaults: {
         done: false
      },
 
      toggle: function() {
         this.save(
   
 
 
 {done: !this.get("done")}
         );
      }
    });
STRUCTURE   Backbone Model
 window.Todo = Backbone.Model.extend({
      defaults: {
         done: false
      },
 
      toggle: function() {
         this.save(
   
 
 
 {done: !this.get("done")}
         );
      }
    });
STRUCTURE   Backbone Collection
 window.TodoList =
 Backbone.Collection.extend({
    model: Todo,
    localStorage: new Store("todos"),
    done: function() {
      return this.filter(function(todo) 
      { return todo.get('done'); });
    },
    remaining: function() {
      return this.without.apply(
        this, this.done());
     }
   });
STRUCTURE   Backbone Collection
 window.TodoList =
 Backbone.Collection.extend({
    model: Todo,
    localStorage: new Store("todos"),
    done: function() {
      return this.filter(function(todo) 
      { return todo.get('done'); });
    },
    remaining: function() {
      return this.without.apply(
        this, this.done());
     }
   });
STRUCTURE   Backbone Collection
 window.TodoList =
 Backbone.Collection.extend({
    model: Todo,
    localStorage: new Store("todos"),
    done: function() {
      return this.filter(function(todo) 
      { return todo.get('done'); });
    },
    remaining: function() {
      return this.without.apply(
        this, this.done());
     }
   });
STRUCTURE   Backbone Collection
 window.TodoList =
 Backbone.Collection.extend({
    model: Todo,
    localStorage: new Store("todos"),
    done: function() {
      return this.filter(function(todo) 
      { return todo.get('done'); });
    },
    remaining: function() {
      return this.without.apply(
        this, this.done());
     }
   });
STRUCTURE   Backbone Collection
 window.TodoList =
 Backbone.Collection.extend({
    model: Todo,
    localStorage: new Store("todos"),
    done: function() {
      return this.filter(function(todo) 
      { return todo.get('done'); });
    },
    remaining: function() {
      return this.without.apply(
        this, this.done());
     }
   });
STRUCTURE   Backbone Collection
 window.TodoList =
 Backbone.Collection.extend({
    model: Todo,
    localStorage: new Store("todos"),
    done: function() {
      return this.filter(function(todo) 
      { return todo.get('done'); });
    },
    remaining: function() {
      return this.without.apply(
        this, this.done());
     }
   });
STRUCTURE   Backbone View
 window.TodoView = Backbone.View.extend({
     tagName: "li",
     template: $("#item-template").template(),
     events: {
       "change   .check"        : "toggleDone",
       "dblclick .todo-content" : "edit",
       "click    .todo-destroy" : "destroy",
       "keypress .todo-input"   :
 "updateOnEnter",
       "blur     .todo-input"   : "close"
     },
STRUCTURE   Backbone View
 window.TodoView = Backbone.View.extend({
     tagName: "li",
     template: $("#item-template").template(),
     events: {
       "change   .check"        : "toggleDone",
       "dblclick .todo-content" : "edit",
       "click    .todo-destroy" : "destroy",
       "keypress .todo-input"   :
 "updateOnEnter",
       "blur     .todo-input"   : "close"
     },
STRUCTURE   Backbone View
 window.TodoView = Backbone.View.extend({
     tagName: "li",
     template: $("#item-template").template(),
     events: {
       "change   .check"        : "toggleDone",
       "dblclick .todo-content" : "edit",
       "click    .todo-destroy" : "destroy",
       "keypress .todo-input"   :
 "updateOnEnter",
       "blur     .todo-input"   : "close"
     },
STRUCTURE   JS Template
 window.TodoView = Backbone.View.extend({
     tagName: "li",
     template: $("#item-template").template(),
     events: {
       "change   .check"        : "toggleDone",
       "dblclick .todo-content" : "edit",
       "click    .todo-destroy" : "destroy",
       "keypress .todo-input"   :
 "updateOnEnter",
       "blur     .todo-input"   : "close"
     },
STRUCTURE   Backbone View
 window.TodoView = Backbone.View.extend({
     tagName: "li",
     template: $("#item-template").template(),
     events: {
       "change   .check"        : "toggleDone",
       "dblclick .todo-content" : "edit",
       "click    .todo-destroy" : "destroy",
       "keypress .todo-input"   :
 "updateOnEnter",
       "blur     .todo-input"   : "close"
     },
STRUCTURE   Backbone View
 initialize: function() {
   _.bindAll(this, 'render', 'close', 'remove',
 'edit');
   this.model.bind('change', this.render);
   this.model.bind('destroy', this.remove);
 },
 render: function() {
   var element = jQuery.tmpl(this.template,
 this.model.toJSON());
   $(this.el).html(element);
   this.input = this.$(".todo-input");
   return this;
 },
STRUCTURE   Backbone View
 initialize: function() {
   _.bindAll(this, 'render', 'close', 'remove',
 'edit');
   this.model.bind('change', this.render);
   this.model.bind('destroy', this.remove);
 },
 render: function() {
   var element = jQuery.tmpl(this.template,
 this.model.toJSON());
   $(this.el).html(element);
   this.input = this.$(".todo-input");
   return this;
 },
STRUCTURE   Backbone View

 toggleDone: function() {
       this.model.toggle();
     },
STRUCTURE   Backbone Router
 var Workspace =
 Backbone.Router.extend({
 
   routes: {
      "help": "help" // #help
   },
 
   help: function() {
      ...
   }
 });
STRUCTURE   Backbone Router
 var Workspace =
 Backbone.Router.extend({
 
   routes: {
      "help": "help" // #help
   },
 
   help: function() {
      ...
   }
 });
STRUCTURE   Backbone Router
 var Workspace =
 Backbone.Router.extend({
 
   routes: {
      "help": "help" // #help
   },
 
   help: function() {
      ...
   }
 });
STRUCTURE   Clean Code
Structure Framework
State Application
Speed Javascript
S TAT E   HTTP/1.1
          “It is a…stateless protocol”
           —RFC 2616 (June 1999)
S TAT E   HTTP/1.1
          “It is a…stateless protocol”
           —RFC 2616 (June 1999)

          cookies

          sessions

          form variables

          URI parameters
S TAT E   Server Owns State




          Client     Server
S TAT E   Request GET   / HTTP/1.1




          Client         Server
S TAT E   Response HTTP/1.1   200 OK




          Client       Server
S TAT E   AJAX asynchronicity




          Client     Server
S TAT E   Infrastructure
                 Client



                 Server
S TAT E   Infrastructure
                 Client



               Web Server
S TAT E   Infrastructure
                  Client



                Web Server

            RESTful Application
S TAT E   Infrastructure
                  Client



                Web Server

            RESTful Application

                 Database
S TAT E   Infrastructure
                   Client

            JavaScript MVC App.


                Web Server

             RESTful API / App.

                 Database
S TAT E   Infrastructure
                  Client

            JavaScript MVC App.

               Local Storage




          Bo nu s!
Structure Framework
State Application
Speed Javascript
SPEED   JavaScript is Fast
        Google v8 JS engine
        —focus on optimizing speed
        It runs in the browser
        —cuts out server requests
        —spares server resources
        —instantaneous UI
SPEED   Data Transport
        JSON data only
        —no markup
SPEED   Data Transport
          JSON data only
          —no markup
{ "id": 1, 
  "first_name": "Philip", 
  "last_name": "Poots", 
  "twitter": "@pootsbook"}
   vs.
"<div id="user_1">n<dl>n<dt>Name</dt>
n<dd>Philip Poots</dd>n<dt>Twitter
handle:</dt>n<dd>@pootsbook</dd>n</dl>
n</div>"
Structure Framework
State Application
Speed Javascript
http://documentcloud.github.com/backbone/
JavaScript Web Apps




@maccman

Weitere ähnliche Inhalte

Was ist angesagt?

Sprout core and performance
Sprout core and performanceSprout core and performance
Sprout core and performance
Yehuda Katz
 
Backbone.js and friends
Backbone.js and friendsBackbone.js and friends
Backbone.js and friends
Good Robot
 
Creating the interfaces of the future with the APIs of today
Creating the interfaces of the future with the APIs of todayCreating the interfaces of the future with the APIs of today
Creating the interfaces of the future with the APIs of today
gerbille
 

Was ist angesagt? (20)

Sprout core and performance
Sprout core and performanceSprout core and performance
Sprout core and performance
 
IndexedDB - Querying and Performance
IndexedDB - Querying and PerformanceIndexedDB - Querying and Performance
IndexedDB - Querying and Performance
 
Backbone.js and friends
Backbone.js and friendsBackbone.js and friends
Backbone.js and friends
 
Angular JS blog tutorial
Angular JS blog tutorialAngular JS blog tutorial
Angular JS blog tutorial
 
Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications  Ember.js - A JavaScript framework for creating ambitious web applications
Ember.js - A JavaScript framework for creating ambitious web applications
 
jQuery: Events, Animation, Ajax
jQuery: Events, Animation, AjaxjQuery: Events, Animation, Ajax
jQuery: Events, Animation, Ajax
 
Backbone js
Backbone jsBackbone js
Backbone js
 
AngularJS Directives
AngularJS DirectivesAngularJS Directives
AngularJS Directives
 
Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1
Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1
Building Single Page Apps with Backbone.js, Coffeescript and Rails 3.1
 
AngulrJS Overview
AngulrJS OverviewAngulrJS Overview
AngulrJS Overview
 
History of jQuery
History of jQueryHistory of jQuery
History of jQuery
 
AngularJS $Provide Service
AngularJS $Provide ServiceAngularJS $Provide Service
AngularJS $Provide Service
 
J query training
J query trainingJ query training
J query training
 
Planbox Backbone MVC
Planbox Backbone MVCPlanbox Backbone MVC
Planbox Backbone MVC
 
jQuery in 15 minutes
jQuery in 15 minutesjQuery in 15 minutes
jQuery in 15 minutes
 
Creating the interfaces of the future with the APIs of today
Creating the interfaces of the future with the APIs of todayCreating the interfaces of the future with the APIs of today
Creating the interfaces of the future with the APIs of today
 
jQuery Presentasion
jQuery PresentasionjQuery Presentasion
jQuery Presentasion
 
A New Baseline for Front-End Devs
A New Baseline for Front-End DevsA New Baseline for Front-End Devs
A New Baseline for Front-End Devs
 
AngularJS Routing
AngularJS RoutingAngularJS Routing
AngularJS Routing
 
jQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingjQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and Bling
 

Ähnlich wie Backbone.js — Introduction to client-side JavaScript MVC

Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011
Chris Alfano
 
Javascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & TricksJavascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & Tricks
Hjörtur Hilmarsson
 
Big Data for each one of us
Big Data for each one of usBig Data for each one of us
Big Data for each one of us
OSCON Byrum
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
Fabio Franzini
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
Igor Bronovskyy
 
Javascript frameworks: Backbone.js
Javascript frameworks: Backbone.jsJavascript frameworks: Backbone.js
Javascript frameworks: Backbone.js
Soós Gábor
 

Ähnlich wie Backbone.js — Introduction to client-side JavaScript MVC (20)

Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
 
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
 
Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011
 
Aplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com BackboneAplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com Backbone
 
Play vs Rails
Play vs RailsPlay vs Rails
Play vs Rails
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
 
Javascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & TricksJavascript MVC & Backbone Tips & Tricks
Javascript MVC & Backbone Tips & Tricks
 
Flask and Angular: An approach to build robust platforms
Flask and Angular:  An approach to build robust platformsFlask and Angular:  An approach to build robust platforms
Flask and Angular: An approach to build robust platforms
 
Writing HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAEWriting HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAE
 
How to React Native
How to React NativeHow to React Native
How to React Native
 
Reactive Type-safe WebComponents
Reactive Type-safe WebComponentsReactive Type-safe WebComponents
Reactive Type-safe WebComponents
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
Big Data for each one of us
Big Data for each one of usBig Data for each one of us
Big Data for each one of us
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
 
Rich Portlet Development in uPortal
Rich Portlet Development in uPortalRich Portlet Development in uPortal
Rich Portlet Development in uPortal
 
Client-side Rendering with AngularJS
Client-side Rendering with AngularJSClient-side Rendering with AngularJS
Client-side Rendering with AngularJS
 
Building iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoBuilding iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" Domino
 
Javascript frameworks: Backbone.js
Javascript frameworks: Backbone.jsJavascript frameworks: Backbone.js
Javascript frameworks: Backbone.js
 
Rails 6 frontend frameworks
Rails 6 frontend frameworksRails 6 frontend frameworks
Rails 6 frontend frameworks
 

Kürzlich hochgeladen

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Kürzlich hochgeladen (20)

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 

Backbone.js — Introduction to client-side JavaScript MVC

  • 1.
  • 2. Philip Poots @pootsbook Ruby Developer Audacio.us 3 18 3
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12. va Sc ri pt Ja
  • 16. $.getJSON("http://example.com/? feed=json&jsonp=?", function(data){ $('#content').html("<a href="" + data[0].permalink + "">" + data[0].title + "</a>"); $('#Date').html(data[0].date); $ ('#Excerpt').html(data[0].excerpt); $('#Excerpt').after("<a href= "" + data[0].permalink + "" class="more">read on &raquo;</ a>"); });
  • 17. STRUCTURE MVC Model View Controller Pattern —1979 Architecture —Separate domain logic & UI Server-Side MVC —Ruby on Rails
  • 18. STRUCTURE MVC on Server
  • 19. STRUCTURE MVC on Client
  • 20. STRUCTURE Backbone Model window.Todo = Backbone.Model.extend({ defaults: { done: false }, toggle: function() { this.save( {done: !this.get("done")} ); } });
  • 21. STRUCTURE Backbone Model window.Todo = Backbone.Model.extend({ defaults: { done: false }, toggle: function() { this.save( {done: !this.get("done")} ); } });
  • 22. STRUCTURE Backbone Model window.Todo = Backbone.Model.extend({ defaults: { done: false }, toggle: function() { this.save( {done: !this.get("done")} ); } });
  • 23. STRUCTURE Backbone Collection window.TodoList = Backbone.Collection.extend({ model: Todo, localStorage: new Store("todos"), done: function() { return this.filter(function(todo) { return todo.get('done'); }); }, remaining: function() { return this.without.apply( this, this.done()); } });
  • 24. STRUCTURE Backbone Collection window.TodoList = Backbone.Collection.extend({ model: Todo, localStorage: new Store("todos"), done: function() { return this.filter(function(todo) { return todo.get('done'); }); }, remaining: function() { return this.without.apply( this, this.done()); } });
  • 25. STRUCTURE Backbone Collection window.TodoList = Backbone.Collection.extend({ model: Todo, localStorage: new Store("todos"), done: function() { return this.filter(function(todo) { return todo.get('done'); }); }, remaining: function() { return this.without.apply( this, this.done()); } });
  • 26. STRUCTURE Backbone Collection window.TodoList = Backbone.Collection.extend({ model: Todo, localStorage: new Store("todos"), done: function() { return this.filter(function(todo) { return todo.get('done'); }); }, remaining: function() { return this.without.apply( this, this.done()); } });
  • 27. STRUCTURE Backbone Collection window.TodoList = Backbone.Collection.extend({ model: Todo, localStorage: new Store("todos"), done: function() { return this.filter(function(todo) { return todo.get('done'); }); }, remaining: function() { return this.without.apply( this, this.done()); } });
  • 28. STRUCTURE Backbone Collection window.TodoList = Backbone.Collection.extend({ model: Todo, localStorage: new Store("todos"), done: function() { return this.filter(function(todo) { return todo.get('done'); }); }, remaining: function() { return this.without.apply( this, this.done()); } });
  • 29. STRUCTURE Backbone View window.TodoView = Backbone.View.extend({ tagName: "li", template: $("#item-template").template(), events: { "change .check" : "toggleDone", "dblclick .todo-content" : "edit", "click .todo-destroy" : "destroy", "keypress .todo-input" : "updateOnEnter", "blur .todo-input" : "close" },
  • 30. STRUCTURE Backbone View window.TodoView = Backbone.View.extend({ tagName: "li", template: $("#item-template").template(), events: { "change .check" : "toggleDone", "dblclick .todo-content" : "edit", "click .todo-destroy" : "destroy", "keypress .todo-input" : "updateOnEnter", "blur .todo-input" : "close" },
  • 31. STRUCTURE Backbone View window.TodoView = Backbone.View.extend({ tagName: "li", template: $("#item-template").template(), events: { "change .check" : "toggleDone", "dblclick .todo-content" : "edit", "click .todo-destroy" : "destroy", "keypress .todo-input" : "updateOnEnter", "blur .todo-input" : "close" },
  • 32. STRUCTURE JS Template window.TodoView = Backbone.View.extend({ tagName: "li", template: $("#item-template").template(), events: { "change .check" : "toggleDone", "dblclick .todo-content" : "edit", "click .todo-destroy" : "destroy", "keypress .todo-input" : "updateOnEnter", "blur .todo-input" : "close" },
  • 33. STRUCTURE Backbone View window.TodoView = Backbone.View.extend({ tagName: "li", template: $("#item-template").template(), events: { "change .check" : "toggleDone", "dblclick .todo-content" : "edit", "click .todo-destroy" : "destroy", "keypress .todo-input" : "updateOnEnter", "blur .todo-input" : "close" },
  • 34. STRUCTURE Backbone View initialize: function() { _.bindAll(this, 'render', 'close', 'remove', 'edit'); this.model.bind('change', this.render); this.model.bind('destroy', this.remove); }, render: function() { var element = jQuery.tmpl(this.template, this.model.toJSON()); $(this.el).html(element); this.input = this.$(".todo-input"); return this; },
  • 35. STRUCTURE Backbone View initialize: function() { _.bindAll(this, 'render', 'close', 'remove', 'edit'); this.model.bind('change', this.render); this.model.bind('destroy', this.remove); }, render: function() { var element = jQuery.tmpl(this.template, this.model.toJSON()); $(this.el).html(element); this.input = this.$(".todo-input"); return this; },
  • 36. STRUCTURE Backbone View toggleDone: function() { this.model.toggle(); },
  • 37. STRUCTURE Backbone Router var Workspace = Backbone.Router.extend({ routes: { "help": "help" // #help }, help: function() { ... } });
  • 38. STRUCTURE Backbone Router var Workspace = Backbone.Router.extend({ routes: { "help": "help" // #help }, help: function() { ... } });
  • 39. STRUCTURE Backbone Router var Workspace = Backbone.Router.extend({ routes: { "help": "help" // #help }, help: function() { ... } });
  • 40. STRUCTURE Clean Code
  • 42. S TAT E HTTP/1.1 “It is a…stateless protocol” —RFC 2616 (June 1999)
  • 43. S TAT E HTTP/1.1 “It is a…stateless protocol” —RFC 2616 (June 1999) cookies sessions form variables URI parameters
  • 44. S TAT E Server Owns State Client Server
  • 45. S TAT E Request GET / HTTP/1.1 Client Server
  • 46. S TAT E Response HTTP/1.1 200 OK Client Server
  • 47. S TAT E AJAX asynchronicity Client Server
  • 48. S TAT E Infrastructure Client Server
  • 49. S TAT E Infrastructure Client Web Server
  • 50. S TAT E Infrastructure Client Web Server RESTful Application
  • 51. S TAT E Infrastructure Client Web Server RESTful Application Database
  • 52. S TAT E Infrastructure Client JavaScript MVC App. Web Server RESTful API / App. Database
  • 53. S TAT E Infrastructure Client JavaScript MVC App. Local Storage Bo nu s!
  • 55. SPEED JavaScript is Fast Google v8 JS engine —focus on optimizing speed It runs in the browser —cuts out server requests —spares server resources —instantaneous UI
  • 56. SPEED Data Transport JSON data only —no markup
  • 57. SPEED Data Transport JSON data only —no markup { "id": 1, "first_name": "Philip", "last_name": "Poots", "twitter": "@pootsbook"} vs. "<div id="user_1">n<dl>n<dt>Name</dt> n<dd>Philip Poots</dd>n<dt>Twitter handle:</dt>n<dd>@pootsbook</dd>n</dl> n</div>"