SlideShare a Scribd company logo
Client-side MVC with Backbone.js (reloaded)
Client-side MVC
with Backbone.js
igloo



igloolab.com       michele.berto.li
 @iloveigloo       @MicheleBertoli
Moniga Del Garda
Lago di Garda


                          jQuery
                      HTML5 UPLOADER                       JOBBERONE
                     igloolab.com/jquery-html5-uploader   jobberone.com




  SHARP SQUARE
igloolab.com/sharpsquare
                                                                  KOALA
                              POMODORO WEBAPP                   koooala.com
                              pomodorowebapp.com
Agenda
Why Backbone.js   06:00 min


Architecture      14:00 min


Real World        05:00 min


Tips & Tricks     06:00 min


Extras            04:00 min


Questions         NaN
Why
Backbone.js
Why Backbone.js


From server-side to client-side
Why Backbone.js


From server-side to client-side
We need efficient tools
Why Backbone.js

jQuery is cool but…
Why Backbone.js

jQuery is cool but…
We have to store object informations into
the DOM

 var list = "";
 $.each(data, function (index, value) {
   list += "<li id="item-" + value.Id + "">" + value.Name + "</li>";
 });
 $("ul").append(list);
Why Backbone.js

jQuery is cool but…
We have to store object informations into
the DOM

 var list = "";
 $.each(data, function (index, value) {
   list += "<li id="item-" + value.Id + "">" + value.Name + "</li>";
 });
 $("ul").append(list);
Why Backbone.js
jQuery is cool but…
jQuery callback hell

 $.getJSON("/Items", function (data) {

   var list = "";
   $.each(data, function (index, value) {
     list += "<li id="item-" + value.Id + "">" + value.Name + "</li>";
   });
   $("ul").append(list);

   $("li").click(function () {
     var $this = $(this);
     var id = $this.attr("id").replace("item-", "");
     $.post("/Items", { id: id }, function () {
        $this.fadeOut(function () {
           $this.remove();
        });
     });
   });

 });
Why Backbone.js
jQuery is cool but…
jQuery callback hell

 $.getJSON("/Items", function (data) {

   var list = "";
   $.each(data, function (index, value) {
     list += "<li id="item-" + value.Id + "">" + value.Name + "</li>";
   });
   $("ul").append(list);

   $("li").click(function () {
     var $this = $(this);
     var id = $this.attr("id").replace("item-", "");
     $.post("/Items", { id: id }, function () {
        $this.fadeOut(function () {
           $this.remove();
        });
     });
   });

 });
Why Backbone.js



“It's all too easy to create JavaScript
applications that end up as tangled piles of
jQuery selectors and callbacks.”
Why Backbone.js

So, what do we need?
 •   Abstraction.
 •   Decoupling UI from Data.
 •   No more callbacks.
Why Backbone.js

So, what do we need? (More practically)
• A RESTful service based data layer.

• Events (to keep UI and data up-to-date).

• A template engine.

• A solid routing system.

• All the above things wrapped into a lightweight
 JavaScript framework.
Why Backbone.js



   It exists and it’s called:
         Backbone.js
Architecture
Architecture



               Oct 13th, 2010




   Jeremy
  Ashkenas
Architecture


http://documentcloud.github.com/backbone

https://github.com/documentcloud/backbone

@documentcloud

#documentcloud on IRC

https://groups.google.com/forum/#!forum/backbonejs
Architecture

Backbone.js gives structure to web
applications by providing models with key-
value binding and custom events,
collections with a rich API of enumerable
functions, views with declarative event
handling, and connects it all to your existing
API over a RESTful JSON interface.
Architecture

Backbone.js gives structure to web
applications by providing models with key-
value binding and custom events,
collections with a rich API of enumerable
functions, views with declarative event
handling, and connects it all to your existing
API over a RESTful JSON interface.
Architecture

Backbone.js gives structure to web
applications by providing models with key-
value binding and custom events,
collections with a rich API of enumerable
functions, views with declarative event
handling, and connects it all to your existing
API over a RESTful JSON interface.
Architecture

Backbone.js gives structure to web
applications by providing models with key-
value binding and custom events,
collections with a rich API of enumerable
functions, views with declarative event
handling, and connects it all to your existing
API over a RESTful JSON interface.
Architecture

Backbone.js gives structure to web
applications by providing models with key-
value binding and custom events,
collections with a rich API of enumerable
functions, views with declarative event
handling, and connects it all to your existing
API over a RESTful JSON interface.
Architecture

Backbone.js gives structure to web
applications by providing models with key-
value binding and custom events,
collections with a rich API of enumerable
functions, views with declarative event
handling, and connects it all to your existing
API over a RESTful JSON interface.
Architecture


Dependencies:
• jQuery or Zepto

•   Underscore.js
•   Json2.js
Architecture


MVC
Model / Collection
Template (View)
View (Controller)
Router
Architecture


MVC
Model / Collection
Template (View)
View (Controller)
Router
Architecture


MVC
Model / Collection
Template (View)
View (Controller)
Router
Architecture


MVC
Model / Collection
Template (View)
View (Controller)
Router
Architecture


MVC
Model / Collection
Template (View)
View (Controller)
Router
Model
• Representing data
  (auto-generated).
• Handling persistence.

• Throws events.

• Reusable.
Architecture
Model / Collection - View - Template - Router - Utilities




Model

•   Fetch                                                   HTTP GET      /url
•   Save (new)                                              HTTP POST     /url
•   Save                                                    HTTP PUT      /url/id
•   Destroy                                                 HTTP DELETE   /url/id
Architecture
Model / Collection - View - Template - Router - Utilities




     var Item = Backbone.Model.extend({
       idAttribute: “Id”,
       urlRoot: “/Items”
     });
Architecture
Model / Collection - View - Template - Router - Utilities




    var item = new Item();
    item.set({
       Name: “Igloo”
    }); // trigger change
    item.save(); // trigger sync
Architecture
Model / Collection - View - Template - Router - Utilities



Model
• extend                                                • toJSON       • changedAttributes
•   constructor / initialize                            • fetch        • previous
•   get                                                 • save         • previousAttributes
•   set                                                 • destroy
•   escape                                              • validate
•   has                                                 • isValid
•   unset                                               • url
•   clear                                               • urlRoot
•   id                                                  • parse
•   idAttribute                                         • clone
•   cid                                                 • isNew
• attributes                                            • change
• defaults                                              • hasChanged
Collection
•   A list of models.
•   Underscore methods.
Architecture
Model / Collection - View - Template - Router - Utilities




    var Items = Backbone.Collection.extend({
      model: Item,
      url: "/Items"
    });
Architecture
Model / Collection - View - Template - Router - Utilities




     var items = new Items();
     items.fetch(); // trigger reset
Architecture
Model / Collection - View - Template - Router - Utilities




     items.comparator = function(item) {
        return item.get("Name");
     };
Architecture
Model / Collection - View - Template - Router - Utilities




Collection
• extend                                      • getByCid     • etch

• model                                       • at           • eset

• constructor / initialize                    • length       • create

• models                                      • comparator

• toJSON                                      • sort

• add                                         • pluck

• remove                                      • url

• get                                         • parse
Architecture
Model / Collection - View - Template - Router - Utilities




Collection                                                  • sortBy
                                                            • groupBy
• forEach (each)                                            • sortedIndex
• map                                                       • shuffle
• reduce (foldl, inject)                                    • toArray
• reduceRight (foldr)                                       • size
• find (detect)                                             • first
• filter (select)                                           • initial
• reject                                                    • rest
• every (all)                                               • last
• some (any)                                                • without
• include                                                   • indexOf
• invoke                                                    • lastIndexOf
• max                                                       • isEmpty
• min                                                       • chain
View
•   Manipulates the DOM.
•   Delegates DOM events.
•   Has a Model / Collection.
Architecture
Model / Collection - View - Template - Router - Utilities




                                                            View

  View (Collection)



                                                                   View (Model)
Architecture
Model / Collection - View - Template - Router - Utilities




   var ListView = Backbone.View.extend({
     el: $("ul"),
     initialize: function () {
        this.collection.bind("reset", this.render, this);
     },
     render: function () {
        this.collection.each(this.addItem, this);
        return this;
     },
     addItem: function (item) {
        var itemView = new ItemView({                       var ItemView = Backbone.View.extend({
           model: item                                        tagName: "li",
        });                                                   render: function () {
        this.$el.append(itemView.el);                           this.$el.text(this.model.get("Name"));
        itemView.render();                                      return this;
     }                                                        }
   });                                                      });
Architecture
Model / Collection - View - Template - Router - Utilities




   var ListView = Backbone.View.extend({
     el: $("ul"),
     initialize: function () {
        this.collection.bind("reset", this.render, this);
     },
     render: function () {
        this.collection.each(this.addItem, this);
        return this;
     },
     addItem: function (item) {
        var itemView = new ItemView({                       var ItemView = Backbone.View.extend({
           model: item                                        tagName: "li",
        });                                                   render: function () {
        this.$el.append(itemView.el);                           this.$el.text(this.model.get("Name"));
        itemView.render();                                      return this;
     }                                                        }
   });                                                      });
Architecture
Model / Collection - View - Template - Router - Utilities




   var ListView = Backbone.View.extend({
     el: $("ul"),
     initialize: function () {
        this.collection.bind("reset", this.render, this);
     },
     render: function () {
        this.collection.each(this.addItem, this);
        return this;
     },
     addItem: function (item) {
        var itemView = new ItemView({                       var ItemView = Backbone.View.extend({
           model: item                                        tagName: "li",
        });                                                   render: function () {
        this.$el.append(itemView.el);                           this.$el.text(this.model.get("Name"));
        itemView.render();                                      return this;
     }                                                        }
   });                                                      });
Architecture
Model / Collection - View - Template - Router - Utilities




   var ListView = Backbone.View.extend({
     el: $("ul"),
     initialize: function () {
        this.collection.bind("reset", this.render, this);
     },
     render: function () {
        this.collection.each(this.addItem, this);
        return this;
     },
     addItem: function (item) {
        var itemView = new ItemView({                       var ItemView = Backbone.View.extend({
           model: item                                        tagName: "li",
        });                                                   render: function () {
        this.$el.append(itemView.el);                           this.$el.text(this.model.get("Name"));
        itemView.render();                                      return this;
     }                                                        }
   });                                                      });
Architecture
Model / Collection - View - Template - Router - Utilities




   var ListView = Backbone.View.extend({
     el: $("ul"),
     initialize: function () {
        this.collection.bind("reset", this.render, this);
     },
     render: function () {
        this.collection.each(this.addItem, this);
        return this;
     },
     addItem: function (item) {
        var itemView = new ItemView({                       var ItemView = Backbone.View.extend({
           model: item                                        tagName: "li",
        });                                                   render: function () {
        this.$el.append(itemView.el);                           this.$el.text(this.model.get("Name"));
        itemView.render();                                      return this;
     }                                                        }
   });                                                      });
Architecture
Model / Collection - View - Template - Router - Utilities




   var ListView = Backbone.View.extend({
     el: $("ul"),
     initialize: function () {
        this.collection.bind("reset", this.render, this);
     },
     render: function () {
        this.collection.each(this.addItem, this);
        return this;
     },
     addItem: function (item) {
        var itemView = new ItemView({                       var ItemView = Backbone.View.extend({
           model: item                                        tagName: "li",
        });                                                   render: function () {
        this.$el.append(itemView.el);                           this.$el.text(this.model.get("Name"));
        itemView.render();                                      return this;
     }                                                        }
   });                                                      });
Architecture
Model / Collection - View - Template - Router - Utilities




     var items = new Items();
     var listView = new ListView({
        collection: items
     });
     items.fetch();
Architecture
Model / Collection - View - Template - Router - Utilities




View
  • $ (jQuery or Zepto)                                     • extend

  • render                                                  • constructor / initialize

  • remove                                                  • el

  • make                                                    • $el

  • delegateEvents                                          • setElement

  • undelegateEvents                                        • attributes
Template            (Underscore.js)


Compiles JavaScript templates into functions
that can be evaluated for rendering.

•   Mustache
•   jQuery-tmpl
Architecture
Model / Collection - View - Template - Router - Utilities




     <script type="text/template" id="item-template">
       <li>
          <%= Name %>
       </li>
     </script>
Architecture
Model / Collection - View - Template - Router - Utilities




     var ItemView = Backbone.View.extend({
       …
       template: _.template($("#item-template").html()),
       ...
       render: function () {
           this.$el.html(this.template(this.model.toJSON()));
           return this;
       }
       …
     });
Router
•   Maps urls to function.
•   Enable history / bookmarking.
Architecture
Model / Collection - View - Template - Router - Utilities




     var AppRouter = Backbone.Router.extend({
       routes: {
          "": "init"
       },
       init: function () {
          …
       }
     });
Architecture
Model / Collection - View - Template - Router - Utilities




   window.AppRouter = Backbone.Router.extend({
     routes: {
        "": "loadInvoices",
        "/add": "addInvoice",
        "/show/:id": "showInvoice",
        "/edit/:id": "editInvoice“
     },
     loadInvoices: function () {
        …
     },
     addInvoice: function () {
        …
     },
     showInvoice: function (id) {
        …
     },
     editInvoice: function (id) {
        …
     }
   });
Architecture
Model / Collection - View - Template - Router - Utilities




Router
• extend
• routes
• constructor / initialize
• route
• navigate
Utilities
•   History
•   Sync
•   Utility
Architecture



                      Model /Collection




                                           Data
 Router        View                       Source


                      Template
Real
World
Real World

Polar management
• Smart invoicing web application



Technologies
• .NET RESTful Web Services / MS SQL
• Backbone.js
Real World

             Polar management
Real World
Real World
Real World


Polar management
 window.AppRouter = Backbone.Router.extend({
   routes: {
      …
      "/modifica/:id": "editInvoice“
   },
   editInvoice: function (id) {
      …
   }
 });
Real World


Polar management
 window.AppRouter = Backbone.Router.extend({
   routes: {
      …
      "/modifica/:id": "editInvoice“
   },
   editInvoice: function (id) {
      …
   }
 });
Real World

Koala
• Social media analytics



Technologies
• .NET RESTful Web Services / RavenDB
• Backbone.js
• Highcharts.js
Real World
Real World
Real World

Koala
 window.Logs = Backbone.Collection.extend({
   model: Log,
   url: "/Data",
   comparator: function (log) {
      return log.get("Date");
   },
   sum: function (field) {
      return this.reduce(function (memo, log) {
         return memo + log.get(field);
      }, 0);
   }
 });
Real World

Koala
 window.Logs = Backbone.Collection.extend({
   model: Log,
   url: "/Data",
   comparator: function (log) {
      return log.get("Date");
   },
   sum: function (field) {
      return this.reduce(function (memo, log) {
         return memo + log.get(field);
      }, 0);
   }
 });
Real World

Koala
 window.Logs = Backbone.Collection.extend({
   model: Log,
   url: "/Data",
   comparator: function (log) {
      return log.get("Date");
   },
   sum: function (field) {
      return this.reduce(function (memo, log) {
         return memo + log.get(field);
      }, 0);
   }
 });
Real World

Cammi
• Custom newsletter engine



Technologies
• .NET RESTful Web Services / MS SQL
• Backbone.js
Real World

Cammi
Real World

Cammi
Real World

Cammi
               Load      Load Groups



                             Fetch
             Load User
                             Fetch


                           Load
               Load      Companies
Real World

             Linkedin
Real World

             Linkedin
Real World

             WunderKit
Real World

             Groupon
Real World


             Basecamp
3




Tips &
Tricks
Tips & Tricks

idAttribute

 idAttribute: “id”

 // CouchDB
 idAttribute: “_id”

 // .NET
 idAttribute: “Id”
Tips & Tricks


            Related Models
Tips & Tricks

Related Models

 var Invoice = Backbone.Model.extend({
   idAttribute: “Id”
 });

 var Invoices = Backbone.Collection.extend({
   model: Invoice,
   url: "/Invoices"
 });
Tips & Tricks

                Related Models
Tips & Tricks

                Related Models
Tips & Tricks

Related Models

 var InvoiceDetail = Backbone.Model.extend({
   idAttribute: “Id”
 });

 var InvoiceDetails = Backbone.Collection.extend({
   model: InvoiceDetail,
   url: "/InvoiceDetails“
 });
Tips & Tricks
Related Models

 var Invoice = Backbone.Model.extend({
   idAttribute: "Id",
   initialize: function () {
      this.setInvoiceDetails();
   },
   setInvoiceDetails: function () {
      this.set({
        InvoiceDetails: new InvoiceDetails(this.get("InvoiceDetails"))
      });
   }
 });
Tips & Tricks

                Related Models
Tips & Tricks

                Related Models
Tips & Tricks
Related Models

 var Invoice = Backbone.Model.extend({
   idAttribute: "Id",
   initialize: function () {
      this.setInvoiceDetails();
      this.bind("sync", this.setInvoiceDetails);
   },
   setInvoiceDetails: function () {
      this.set({
        InvoiceDetails: new InvoiceDetails(this.get("InvoiceDetails"))
      });
   }
 });
Extras
Extras

Plugins
• Backbone-Nested
• Backbone.Memento
• Backbone.Validations
• Backbone.localStorage
• backbone.couchdb.js
• …
https://github.com/documentcloud/backbone/wiki/Extensions%2C-
Plugins%2C-Resources
Extras

TDD - Jasmine

 describe("Todo", function() {


   it("Should have a title", function() {
       var todo = new Todo();
       expect(todo.get("title")).toBeDefined();
   });


 });
Extras

Backbone is anti-SEO
http://www.spiffyui.org#!css
http://www.spiffyui.org?_escaped_fragment_=css


http://coding.smashingmagazine.com/2011/09/27/searchable-dynamic-
content-with-ajax-crawling/
Extras


• http://sproutcore.com (Apple/iCloud)

• http://knockoutjs.com

• http://emberjs.com

• http://batmanjs.org (Shopify)
Extras



Cheat Sheet
• http://www.igloolab.com/downloads/backbone-cheatsheet.pdf
Backbone.js
+
• Lightweight
• Powerful
• Code is clean (and maintainable)


-
• Too verbose (for small applications)
3
  Lago di Garda


Questions ?

    Grazie
    www.igloolab.com
      @iloveigloo

More Related Content

What's hot (20)

JQuery
JQueryJQuery
JQuery
Rahul Jain
 
ORM Pink Unicorns
ORM Pink UnicornsORM Pink Unicorns
ORM Pink Unicorns
Ortus Solutions, Corp
 
Nothing Hard Baked: Designing the Inclusive Web
Nothing Hard Baked: Designing the Inclusive WebNothing Hard Baked: Designing the Inclusive Web
Nothing Hard Baked: Designing the Inclusive Web
colinbdclark
 
Django at Scale
Django at ScaleDjango at Scale
Django at Scale
bretthoerner
 
An in-depth look at jQuery UI
An in-depth look at jQuery UIAn in-depth look at jQuery UI
An in-depth look at jQuery UI
Paul Bakaus
 
iOS 7 SDK特訓班
iOS 7 SDK特訓班iOS 7 SDK特訓班
iOS 7 SDK特訓班
彼得潘 Pan
 
SharePoint and jQuery Essentials
SharePoint and jQuery EssentialsSharePoint and jQuery Essentials
SharePoint and jQuery Essentials
Mark Rackley
 
Assetic (OSCON)
Assetic (OSCON)Assetic (OSCON)
Assetic (OSCON)
Kris Wallsmith
 
fuser interface-development-using-jquery
fuser interface-development-using-jqueryfuser interface-development-using-jquery
fuser interface-development-using-jquery
Kostas Mavridis
 
Killing Shark-Riding Dinosaurs with ORM
Killing Shark-Riding Dinosaurs with ORMKilling Shark-Riding Dinosaurs with ORM
Killing Shark-Riding Dinosaurs with ORM
Ortus Solutions, Corp
 
Iniciando com jquery
Iniciando com jqueryIniciando com jquery
Iniciando com jquery
Danilo Sousa
 
Pier - no kernel left behind
Pier - no kernel left behindPier - no kernel left behind
Pier - no kernel left behind
Nick Ager
 
Get started with YUI
Get started with YUIGet started with YUI
Get started with YUI
Adam Lu
 
OOCSS for JavaScript Pirates jQcon Boston
OOCSS for JavaScript Pirates jQcon BostonOOCSS for JavaScript Pirates jQcon Boston
OOCSS for JavaScript Pirates jQcon Boston
John Hann
 
Bcblackpool jquery tips
Bcblackpool jquery tipsBcblackpool jquery tips
Bcblackpool jquery tips
Jack Franklin
 
JavaScript Library Overview (Ajax Exp West 2007)
JavaScript Library Overview (Ajax Exp West 2007)JavaScript Library Overview (Ajax Exp West 2007)
JavaScript Library Overview (Ajax Exp West 2007)
jeresig
 
Best Guide for Javascript Objects
Best Guide for Javascript ObjectsBest Guide for Javascript Objects
Best Guide for Javascript Objects
Muhammad khurram khan
 
Real World MVC
Real World MVCReal World MVC
Real World MVC
James Johnson
 
Scala ActiveRecord
Scala ActiveRecordScala ActiveRecord
Scala ActiveRecord
scalaconfjp
 
Omnisearch in AEM 6.2 - Search All the Things
Omnisearch in AEM 6.2 - Search All the ThingsOmnisearch in AEM 6.2 - Search All the Things
Omnisearch in AEM 6.2 - Search All the Things
Justin Edelson
 
Nothing Hard Baked: Designing the Inclusive Web
Nothing Hard Baked: Designing the Inclusive WebNothing Hard Baked: Designing the Inclusive Web
Nothing Hard Baked: Designing the Inclusive Web
colinbdclark
 
An in-depth look at jQuery UI
An in-depth look at jQuery UIAn in-depth look at jQuery UI
An in-depth look at jQuery UI
Paul Bakaus
 
SharePoint and jQuery Essentials
SharePoint and jQuery EssentialsSharePoint and jQuery Essentials
SharePoint and jQuery Essentials
Mark Rackley
 
fuser interface-development-using-jquery
fuser interface-development-using-jqueryfuser interface-development-using-jquery
fuser interface-development-using-jquery
Kostas Mavridis
 
Killing Shark-Riding Dinosaurs with ORM
Killing Shark-Riding Dinosaurs with ORMKilling Shark-Riding Dinosaurs with ORM
Killing Shark-Riding Dinosaurs with ORM
Ortus Solutions, Corp
 
Iniciando com jquery
Iniciando com jqueryIniciando com jquery
Iniciando com jquery
Danilo Sousa
 
Pier - no kernel left behind
Pier - no kernel left behindPier - no kernel left behind
Pier - no kernel left behind
Nick Ager
 
Get started with YUI
Get started with YUIGet started with YUI
Get started with YUI
Adam Lu
 
OOCSS for JavaScript Pirates jQcon Boston
OOCSS for JavaScript Pirates jQcon BostonOOCSS for JavaScript Pirates jQcon Boston
OOCSS for JavaScript Pirates jQcon Boston
John Hann
 
Bcblackpool jquery tips
Bcblackpool jquery tipsBcblackpool jquery tips
Bcblackpool jquery tips
Jack Franklin
 
JavaScript Library Overview (Ajax Exp West 2007)
JavaScript Library Overview (Ajax Exp West 2007)JavaScript Library Overview (Ajax Exp West 2007)
JavaScript Library Overview (Ajax Exp West 2007)
jeresig
 
Scala ActiveRecord
Scala ActiveRecordScala ActiveRecord
Scala ActiveRecord
scalaconfjp
 
Omnisearch in AEM 6.2 - Search All the Things
Omnisearch in AEM 6.2 - Search All the ThingsOmnisearch in AEM 6.2 - Search All the Things
Omnisearch in AEM 6.2 - Search All the Things
Justin Edelson
 

Viewers also liked (20)

#4 - CSS Selectors, CSS3 and Web typography
#4 - CSS Selectors, CSS3 and Web typography#4 - CSS Selectors, CSS3 and Web typography
#4 - CSS Selectors, CSS3 and Web typography
iloveigloo
 
#1 - HTML5 Overview
#1 - HTML5 Overview#1 - HTML5 Overview
#1 - HTML5 Overview
iloveigloo
 
#3 - Sectioning content and outline view
#3 - Sectioning content and outline view#3 - Sectioning content and outline view
#3 - Sectioning content and outline view
iloveigloo
 
#7 - Client-side web apps, MVC and jQuery
#7 - Client-side web apps, MVC and jQuery#7 - Client-side web apps, MVC and jQuery
#7 - Client-side web apps, MVC and jQuery
iloveigloo
 
#6 - Template Engine: Mustache.js
#6 - Template Engine: Mustache.js#6 - Template Engine: Mustache.js
#6 - Template Engine: Mustache.js
iloveigloo
 
#5 - CSS3 Gradients and Backgrounds
#5 - CSS3 Gradients and Backgrounds#5 - CSS3 Gradients and Backgrounds
#5 - CSS3 Gradients and Backgrounds
iloveigloo
 
Shoppingsquare
ShoppingsquareShoppingsquare
Shoppingsquare
iloveigloo
 
#2 - CSS Layouts Overview
#2 - CSS Layouts Overview#2 - CSS Layouts Overview
#2 - CSS Layouts Overview
iloveigloo
 
CSS3: Ripe and Ready
CSS3: Ripe and ReadyCSS3: Ripe and Ready
CSS3: Ripe and Ready
Denise Jacobs
 
كتاب تعلم Html5 css3
كتاب تعلم Html5 css3كتاب تعلم Html5 css3
كتاب تعلم Html5 css3
titifcom
 
Magic of Ruby
Magic of RubyMagic of Ruby
Magic of Ruby
Gabriele Lana
 
Parse Everything With Elixir
Parse Everything With ElixirParse Everything With Elixir
Parse Everything With Elixir
Gabriele Lana
 
Beyond Phoenix
Beyond PhoenixBeyond Phoenix
Beyond Phoenix
Gabriele Lana
 
Estilo & CSS3
Estilo & CSS3Estilo & CSS3
Estilo & CSS3
ccarruitero
 
CSS3: A practical introduction (FT2010 talk)
CSS3: A practical introduction (FT2010 talk)CSS3: A practical introduction (FT2010 talk)
CSS3: A practical introduction (FT2010 talk)
Lea Verou
 
CSS3 secrets: 10 things you might not know about CSS3
CSS3 secrets: 10 things you might not know about CSS3CSS3 secrets: 10 things you might not know about CSS3
CSS3 secrets: 10 things you might not know about CSS3
Lea Verou
 
Conoce HTML5 y CSS3
Conoce HTML5 y CSS3Conoce HTML5 y CSS3
Conoce HTML5 y CSS3
Marta Armada
 
Fundamental CSS3
Fundamental CSS3Fundamental CSS3
Fundamental CSS3
Achmad Solichin
 
Fundamental HTML5
Fundamental HTML5Fundamental HTML5
Fundamental HTML5
Achmad Solichin
 
#4 - CSS Selectors, CSS3 and Web typography
#4 - CSS Selectors, CSS3 and Web typography#4 - CSS Selectors, CSS3 and Web typography
#4 - CSS Selectors, CSS3 and Web typography
iloveigloo
 
#1 - HTML5 Overview
#1 - HTML5 Overview#1 - HTML5 Overview
#1 - HTML5 Overview
iloveigloo
 
#3 - Sectioning content and outline view
#3 - Sectioning content and outline view#3 - Sectioning content and outline view
#3 - Sectioning content and outline view
iloveigloo
 
#7 - Client-side web apps, MVC and jQuery
#7 - Client-side web apps, MVC and jQuery#7 - Client-side web apps, MVC and jQuery
#7 - Client-side web apps, MVC and jQuery
iloveigloo
 
#6 - Template Engine: Mustache.js
#6 - Template Engine: Mustache.js#6 - Template Engine: Mustache.js
#6 - Template Engine: Mustache.js
iloveigloo
 
#5 - CSS3 Gradients and Backgrounds
#5 - CSS3 Gradients and Backgrounds#5 - CSS3 Gradients and Backgrounds
#5 - CSS3 Gradients and Backgrounds
iloveigloo
 
Shoppingsquare
ShoppingsquareShoppingsquare
Shoppingsquare
iloveigloo
 
#2 - CSS Layouts Overview
#2 - CSS Layouts Overview#2 - CSS Layouts Overview
#2 - CSS Layouts Overview
iloveigloo
 
CSS3: Ripe and Ready
CSS3: Ripe and ReadyCSS3: Ripe and Ready
CSS3: Ripe and Ready
Denise Jacobs
 
كتاب تعلم Html5 css3
كتاب تعلم Html5 css3كتاب تعلم Html5 css3
كتاب تعلم Html5 css3
titifcom
 
Parse Everything With Elixir
Parse Everything With ElixirParse Everything With Elixir
Parse Everything With Elixir
Gabriele Lana
 
CSS3: A practical introduction (FT2010 talk)
CSS3: A practical introduction (FT2010 talk)CSS3: A practical introduction (FT2010 talk)
CSS3: A practical introduction (FT2010 talk)
Lea Verou
 
CSS3 secrets: 10 things you might not know about CSS3
CSS3 secrets: 10 things you might not know about CSS3CSS3 secrets: 10 things you might not know about CSS3
CSS3 secrets: 10 things you might not know about CSS3
Lea Verou
 
Conoce HTML5 y CSS3
Conoce HTML5 y CSS3Conoce HTML5 y CSS3
Conoce HTML5 y CSS3
Marta Armada
 
Ad

Similar to Client-side MVC with Backbone.js (reloaded) (20)

Backbonejs for beginners
Backbonejs for beginnersBackbonejs for beginners
Backbonejs for beginners
Divakar Gu
 
前端MVC之BackboneJS
前端MVC之BackboneJS前端MVC之BackboneJS
前端MVC之BackboneJS
Zhang Xiaoxue
 
DevLOVE Beautiful Development - 第一幕 陽の巻
DevLOVE Beautiful Development - 第一幕 陽の巻DevLOVE Beautiful Development - 第一幕 陽の巻
DevLOVE Beautiful Development - 第一幕 陽の巻
都元ダイスケ Miyamoto
 
User Interface Development with jQuery
User Interface Development with jQueryUser Interface Development with jQuery
User Interface Development with jQuery
colinbdclark
 
Django introduction @ UGent
Django introduction @ UGentDjango introduction @ UGent
Django introduction @ UGent
kevinvw
 
Play Framework and Activator
Play Framework and ActivatorPlay Framework and Activator
Play Framework and Activator
Kevin Webber
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
Nick Lee
 
CUST-1 Share Document Library Extension Points
CUST-1 Share Document Library Extension PointsCUST-1 Share Document Library Extension Points
CUST-1 Share Document Library Extension Points
Alfresco Software
 
JS Essence
JS EssenceJS Essence
JS Essence
Uladzimir Piatryka
 
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD CombinationLotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Sean Burgess
 
State of search | drupalcamp ghent
State of search | drupalcamp ghentState of search | drupalcamp ghent
State of search | drupalcamp ghent
Joris Vercammen
 
Awesome html with ujs, jQuery and coffeescript
Awesome html with ujs, jQuery and coffeescriptAwesome html with ujs, jQuery and coffeescript
Awesome html with ujs, jQuery and coffeescript
Amir Barylko
 
Python & Django TTT
Python & Django TTTPython & Django TTT
Python & Django TTT
kevinvw
 
State of search | drupal dinner
State of search | drupal dinnerState of search | drupal dinner
State of search | drupal dinner
Joris Vercammen
 
Modular & Event driven UI Architecture
Modular & Event driven UI ArchitectureModular & Event driven UI Architecture
Modular & Event driven UI Architecture
Vytautas Butkus
 
Web2.0 with jQuery in English
Web2.0 with jQuery in EnglishWeb2.0 with jQuery in English
Web2.0 with jQuery in English
Lau Bech Lauritzen
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
Alive Kuo
 
コードで学ぶドメイン駆動設計入門
コードで学ぶドメイン駆動設計入門コードで学ぶドメイン駆動設計入門
コードで学ぶドメイン駆動設計入門
潤一 加藤
 
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
 
Deep Dive: Alfresco Core Repository (... embedded in a micro-services style a...
Deep Dive: Alfresco Core Repository (... embedded in a micro-services style a...Deep Dive: Alfresco Core Repository (... embedded in a micro-services style a...
Deep Dive: Alfresco Core Repository (... embedded in a micro-services style a...
J V
 
Backbonejs for beginners
Backbonejs for beginnersBackbonejs for beginners
Backbonejs for beginners
Divakar Gu
 
前端MVC之BackboneJS
前端MVC之BackboneJS前端MVC之BackboneJS
前端MVC之BackboneJS
Zhang Xiaoxue
 
DevLOVE Beautiful Development - 第一幕 陽の巻
DevLOVE Beautiful Development - 第一幕 陽の巻DevLOVE Beautiful Development - 第一幕 陽の巻
DevLOVE Beautiful Development - 第一幕 陽の巻
都元ダイスケ Miyamoto
 
User Interface Development with jQuery
User Interface Development with jQueryUser Interface Development with jQuery
User Interface Development with jQuery
colinbdclark
 
Django introduction @ UGent
Django introduction @ UGentDjango introduction @ UGent
Django introduction @ UGent
kevinvw
 
Play Framework and Activator
Play Framework and ActivatorPlay Framework and Activator
Play Framework and Activator
Kevin Webber
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
Nick Lee
 
CUST-1 Share Document Library Extension Points
CUST-1 Share Document Library Extension PointsCUST-1 Share Document Library Extension Points
CUST-1 Share Document Library Extension Points
Alfresco Software
 
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD CombinationLotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Sean Burgess
 
State of search | drupalcamp ghent
State of search | drupalcamp ghentState of search | drupalcamp ghent
State of search | drupalcamp ghent
Joris Vercammen
 
Awesome html with ujs, jQuery and coffeescript
Awesome html with ujs, jQuery and coffeescriptAwesome html with ujs, jQuery and coffeescript
Awesome html with ujs, jQuery and coffeescript
Amir Barylko
 
Python & Django TTT
Python & Django TTTPython & Django TTT
Python & Django TTT
kevinvw
 
State of search | drupal dinner
State of search | drupal dinnerState of search | drupal dinner
State of search | drupal dinner
Joris Vercammen
 
Modular & Event driven UI Architecture
Modular & Event driven UI ArchitectureModular & Event driven UI Architecture
Modular & Event driven UI Architecture
Vytautas Butkus
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
Alive Kuo
 
コードで学ぶドメイン駆動設計入門
コードで学ぶドメイン駆動設計入門コードで学ぶドメイン駆動設計入門
コードで学ぶドメイン駆動設計入門
潤一 加藤
 
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
 
Deep Dive: Alfresco Core Repository (... embedded in a micro-services style a...
Deep Dive: Alfresco Core Repository (... embedded in a micro-services style a...Deep Dive: Alfresco Core Repository (... embedded in a micro-services style a...
Deep Dive: Alfresco Core Repository (... embedded in a micro-services style a...
J V
 
Ad

Recently uploaded (20)

cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdfcnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Impelsys Inc.
 
Improving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevExImproving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevEx
Justin Reock
 
Introduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUEIntroduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUE
Google Developer Group On Campus European Universities in Egypt
 
LSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection FunctionLSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection Function
Takahiro Harada
 
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptxISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
AyilurRamnath1
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI ProfessionalOracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
7 Salesforce Data Cloud Best Practices.pdf
7 Salesforce Data Cloud Best Practices.pdf7 Salesforce Data Cloud Best Practices.pdf
7 Salesforce Data Cloud Best Practices.pdf
Minuscule Technologies
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
angelo60207
 
Data Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any ApplicationData Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any Application
Safe Software
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementaryMurdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
“How Qualcomm Is Powering AI-driven Multimedia at the Edge,” a Presentation f...
“How Qualcomm Is Powering AI-driven Multimedia at the Edge,” a Presentation f...“How Qualcomm Is Powering AI-driven Multimedia at the Edge,” a Presentation f...
“How Qualcomm Is Powering AI-driven Multimedia at the Edge,” a Presentation f...
Edge AI and Vision Alliance
 
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdfHow Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
Rejig Digital
 
Jeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software DeveloperJeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software Developer
Jeremy Millul
 
MCP vs A2A vs ACP: Choosing the Right Protocol | Bluebash
MCP vs A2A vs ACP: Choosing the Right Protocol | BluebashMCP vs A2A vs ACP: Choosing the Right Protocol | Bluebash
MCP vs A2A vs ACP: Choosing the Right Protocol | Bluebash
Bluebash
 
If You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FMEIf You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FME
Safe Software
 
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOMEstablish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Anchore
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Safe Software
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdfcnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Impelsys Inc.
 
Improving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevExImproving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevEx
Justin Reock
 
LSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection FunctionLSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection Function
Takahiro Harada
 
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptxISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
AyilurRamnath1
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI ProfessionalOracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
7 Salesforce Data Cloud Best Practices.pdf
7 Salesforce Data Cloud Best Practices.pdf7 Salesforce Data Cloud Best Practices.pdf
7 Salesforce Data Cloud Best Practices.pdf
Minuscule Technologies
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
angelo60207
 
Data Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any ApplicationData Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any Application
Safe Software
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementaryMurdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
“How Qualcomm Is Powering AI-driven Multimedia at the Edge,” a Presentation f...
“How Qualcomm Is Powering AI-driven Multimedia at the Edge,” a Presentation f...“How Qualcomm Is Powering AI-driven Multimedia at the Edge,” a Presentation f...
“How Qualcomm Is Powering AI-driven Multimedia at the Edge,” a Presentation f...
Edge AI and Vision Alliance
 
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdfHow Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
Rejig Digital
 
Jeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software DeveloperJeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software Developer
Jeremy Millul
 
MCP vs A2A vs ACP: Choosing the Right Protocol | Bluebash
MCP vs A2A vs ACP: Choosing the Right Protocol | BluebashMCP vs A2A vs ACP: Choosing the Right Protocol | Bluebash
MCP vs A2A vs ACP: Choosing the Right Protocol | Bluebash
Bluebash
 
If You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FMEIf You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FME
Safe Software
 
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOMEstablish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Anchore
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025Developing Schemas with FME and Excel - Peak of Data & AI 2025
Developing Schemas with FME and Excel - Peak of Data & AI 2025
Safe Software
 

Client-side MVC with Backbone.js (reloaded)

  • 3. igloo igloolab.com michele.berto.li @iloveigloo @MicheleBertoli
  • 5. Lago di Garda jQuery HTML5 UPLOADER JOBBERONE igloolab.com/jquery-html5-uploader jobberone.com SHARP SQUARE igloolab.com/sharpsquare KOALA POMODORO WEBAPP koooala.com pomodorowebapp.com
  • 7. Why Backbone.js 06:00 min Architecture 14:00 min Real World 05:00 min Tips & Tricks 06:00 min Extras 04:00 min Questions NaN
  • 10. Why Backbone.js From server-side to client-side We need efficient tools
  • 12. Why Backbone.js jQuery is cool but… We have to store object informations into the DOM var list = ""; $.each(data, function (index, value) { list += "<li id="item-" + value.Id + "">" + value.Name + "</li>"; }); $("ul").append(list);
  • 13. Why Backbone.js jQuery is cool but… We have to store object informations into the DOM var list = ""; $.each(data, function (index, value) { list += "<li id="item-" + value.Id + "">" + value.Name + "</li>"; }); $("ul").append(list);
  • 14. Why Backbone.js jQuery is cool but… jQuery callback hell $.getJSON("/Items", function (data) { var list = ""; $.each(data, function (index, value) { list += "<li id="item-" + value.Id + "">" + value.Name + "</li>"; }); $("ul").append(list); $("li").click(function () { var $this = $(this); var id = $this.attr("id").replace("item-", ""); $.post("/Items", { id: id }, function () { $this.fadeOut(function () { $this.remove(); }); }); }); });
  • 15. Why Backbone.js jQuery is cool but… jQuery callback hell $.getJSON("/Items", function (data) { var list = ""; $.each(data, function (index, value) { list += "<li id="item-" + value.Id + "">" + value.Name + "</li>"; }); $("ul").append(list); $("li").click(function () { var $this = $(this); var id = $this.attr("id").replace("item-", ""); $.post("/Items", { id: id }, function () { $this.fadeOut(function () { $this.remove(); }); }); }); });
  • 16. Why Backbone.js “It's all too easy to create JavaScript applications that end up as tangled piles of jQuery selectors and callbacks.”
  • 17. Why Backbone.js So, what do we need? • Abstraction. • Decoupling UI from Data. • No more callbacks.
  • 18. Why Backbone.js So, what do we need? (More practically) • A RESTful service based data layer. • Events (to keep UI and data up-to-date). • A template engine. • A solid routing system. • All the above things wrapped into a lightweight JavaScript framework.
  • 19. Why Backbone.js It exists and it’s called: Backbone.js
  • 21. Architecture Oct 13th, 2010 Jeremy Ashkenas
  • 23. Architecture Backbone.js gives structure to web applications by providing models with key- value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.
  • 24. Architecture Backbone.js gives structure to web applications by providing models with key- value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.
  • 25. Architecture Backbone.js gives structure to web applications by providing models with key- value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.
  • 26. Architecture Backbone.js gives structure to web applications by providing models with key- value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.
  • 27. Architecture Backbone.js gives structure to web applications by providing models with key- value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.
  • 28. Architecture Backbone.js gives structure to web applications by providing models with key- value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.
  • 29. Architecture Dependencies: • jQuery or Zepto • Underscore.js • Json2.js
  • 30. Architecture MVC Model / Collection Template (View) View (Controller) Router
  • 31. Architecture MVC Model / Collection Template (View) View (Controller) Router
  • 32. Architecture MVC Model / Collection Template (View) View (Controller) Router
  • 33. Architecture MVC Model / Collection Template (View) View (Controller) Router
  • 34. Architecture MVC Model / Collection Template (View) View (Controller) Router
  • 35. Model • Representing data (auto-generated). • Handling persistence. • Throws events. • Reusable.
  • 36. Architecture Model / Collection - View - Template - Router - Utilities Model • Fetch HTTP GET /url • Save (new) HTTP POST /url • Save HTTP PUT /url/id • Destroy HTTP DELETE /url/id
  • 37. Architecture Model / Collection - View - Template - Router - Utilities var Item = Backbone.Model.extend({ idAttribute: “Id”, urlRoot: “/Items” });
  • 38. Architecture Model / Collection - View - Template - Router - Utilities var item = new Item(); item.set({ Name: “Igloo” }); // trigger change item.save(); // trigger sync
  • 39. Architecture Model / Collection - View - Template - Router - Utilities Model • extend • toJSON • changedAttributes • constructor / initialize • fetch • previous • get • save • previousAttributes • set • destroy • escape • validate • has • isValid • unset • url • clear • urlRoot • id • parse • idAttribute • clone • cid • isNew • attributes • change • defaults • hasChanged
  • 40. Collection • A list of models. • Underscore methods.
  • 41. Architecture Model / Collection - View - Template - Router - Utilities var Items = Backbone.Collection.extend({ model: Item, url: "/Items" });
  • 42. Architecture Model / Collection - View - Template - Router - Utilities var items = new Items(); items.fetch(); // trigger reset
  • 43. Architecture Model / Collection - View - Template - Router - Utilities items.comparator = function(item) { return item.get("Name"); };
  • 44. Architecture Model / Collection - View - Template - Router - Utilities Collection • extend • getByCid • etch • model • at • eset • constructor / initialize • length • create • models • comparator • toJSON • sort • add • pluck • remove • url • get • parse
  • 45. Architecture Model / Collection - View - Template - Router - Utilities Collection • sortBy • groupBy • forEach (each) • sortedIndex • map • shuffle • reduce (foldl, inject) • toArray • reduceRight (foldr) • size • find (detect) • first • filter (select) • initial • reject • rest • every (all) • last • some (any) • without • include • indexOf • invoke • lastIndexOf • max • isEmpty • min • chain
  • 46. View • Manipulates the DOM. • Delegates DOM events. • Has a Model / Collection.
  • 47. Architecture Model / Collection - View - Template - Router - Utilities View View (Collection) View (Model)
  • 48. Architecture Model / Collection - View - Template - Router - Utilities var ListView = Backbone.View.extend({ el: $("ul"), initialize: function () { this.collection.bind("reset", this.render, this); }, render: function () { this.collection.each(this.addItem, this); return this; }, addItem: function (item) { var itemView = new ItemView({ var ItemView = Backbone.View.extend({ model: item tagName: "li", }); render: function () { this.$el.append(itemView.el); this.$el.text(this.model.get("Name")); itemView.render(); return this; } } }); });
  • 49. Architecture Model / Collection - View - Template - Router - Utilities var ListView = Backbone.View.extend({ el: $("ul"), initialize: function () { this.collection.bind("reset", this.render, this); }, render: function () { this.collection.each(this.addItem, this); return this; }, addItem: function (item) { var itemView = new ItemView({ var ItemView = Backbone.View.extend({ model: item tagName: "li", }); render: function () { this.$el.append(itemView.el); this.$el.text(this.model.get("Name")); itemView.render(); return this; } } }); });
  • 50. Architecture Model / Collection - View - Template - Router - Utilities var ListView = Backbone.View.extend({ el: $("ul"), initialize: function () { this.collection.bind("reset", this.render, this); }, render: function () { this.collection.each(this.addItem, this); return this; }, addItem: function (item) { var itemView = new ItemView({ var ItemView = Backbone.View.extend({ model: item tagName: "li", }); render: function () { this.$el.append(itemView.el); this.$el.text(this.model.get("Name")); itemView.render(); return this; } } }); });
  • 51. Architecture Model / Collection - View - Template - Router - Utilities var ListView = Backbone.View.extend({ el: $("ul"), initialize: function () { this.collection.bind("reset", this.render, this); }, render: function () { this.collection.each(this.addItem, this); return this; }, addItem: function (item) { var itemView = new ItemView({ var ItemView = Backbone.View.extend({ model: item tagName: "li", }); render: function () { this.$el.append(itemView.el); this.$el.text(this.model.get("Name")); itemView.render(); return this; } } }); });
  • 52. Architecture Model / Collection - View - Template - Router - Utilities var ListView = Backbone.View.extend({ el: $("ul"), initialize: function () { this.collection.bind("reset", this.render, this); }, render: function () { this.collection.each(this.addItem, this); return this; }, addItem: function (item) { var itemView = new ItemView({ var ItemView = Backbone.View.extend({ model: item tagName: "li", }); render: function () { this.$el.append(itemView.el); this.$el.text(this.model.get("Name")); itemView.render(); return this; } } }); });
  • 53. Architecture Model / Collection - View - Template - Router - Utilities var ListView = Backbone.View.extend({ el: $("ul"), initialize: function () { this.collection.bind("reset", this.render, this); }, render: function () { this.collection.each(this.addItem, this); return this; }, addItem: function (item) { var itemView = new ItemView({ var ItemView = Backbone.View.extend({ model: item tagName: "li", }); render: function () { this.$el.append(itemView.el); this.$el.text(this.model.get("Name")); itemView.render(); return this; } } }); });
  • 54. Architecture Model / Collection - View - Template - Router - Utilities var items = new Items(); var listView = new ListView({ collection: items }); items.fetch();
  • 55. Architecture Model / Collection - View - Template - Router - Utilities View • $ (jQuery or Zepto) • extend • render • constructor / initialize • remove • el • make • $el • delegateEvents • setElement • undelegateEvents • attributes
  • 56. Template (Underscore.js) Compiles JavaScript templates into functions that can be evaluated for rendering. • Mustache • jQuery-tmpl
  • 57. Architecture Model / Collection - View - Template - Router - Utilities <script type="text/template" id="item-template"> <li> <%= Name %> </li> </script>
  • 58. Architecture Model / Collection - View - Template - Router - Utilities var ItemView = Backbone.View.extend({ … template: _.template($("#item-template").html()), ... render: function () { this.$el.html(this.template(this.model.toJSON())); return this; } … });
  • 59. Router • Maps urls to function. • Enable history / bookmarking.
  • 60. Architecture Model / Collection - View - Template - Router - Utilities var AppRouter = Backbone.Router.extend({ routes: { "": "init" }, init: function () { … } });
  • 61. Architecture Model / Collection - View - Template - Router - Utilities window.AppRouter = Backbone.Router.extend({ routes: { "": "loadInvoices", "/add": "addInvoice", "/show/:id": "showInvoice", "/edit/:id": "editInvoice“ }, loadInvoices: function () { … }, addInvoice: function () { … }, showInvoice: function (id) { … }, editInvoice: function (id) { … } });
  • 62. Architecture Model / Collection - View - Template - Router - Utilities Router • extend • routes • constructor / initialize • route • navigate
  • 63. Utilities • History • Sync • Utility
  • 64. Architecture Model /Collection Data Router View Source Template
  • 66. Real World Polar management • Smart invoicing web application Technologies • .NET RESTful Web Services / MS SQL • Backbone.js
  • 67. Real World Polar management
  • 70. Real World Polar management window.AppRouter = Backbone.Router.extend({ routes: { … "/modifica/:id": "editInvoice“ }, editInvoice: function (id) { … } });
  • 71. Real World Polar management window.AppRouter = Backbone.Router.extend({ routes: { … "/modifica/:id": "editInvoice“ }, editInvoice: function (id) { … } });
  • 72. Real World Koala • Social media analytics Technologies • .NET RESTful Web Services / RavenDB • Backbone.js • Highcharts.js
  • 75. Real World Koala window.Logs = Backbone.Collection.extend({ model: Log, url: "/Data", comparator: function (log) { return log.get("Date"); }, sum: function (field) { return this.reduce(function (memo, log) { return memo + log.get(field); }, 0); } });
  • 76. Real World Koala window.Logs = Backbone.Collection.extend({ model: Log, url: "/Data", comparator: function (log) { return log.get("Date"); }, sum: function (field) { return this.reduce(function (memo, log) { return memo + log.get(field); }, 0); } });
  • 77. Real World Koala window.Logs = Backbone.Collection.extend({ model: Log, url: "/Data", comparator: function (log) { return log.get("Date"); }, sum: function (field) { return this.reduce(function (memo, log) { return memo + log.get(field); }, 0); } });
  • 78. Real World Cammi • Custom newsletter engine Technologies • .NET RESTful Web Services / MS SQL • Backbone.js
  • 81. Real World Cammi Load Load Groups Fetch Load User Fetch Load Load Companies
  • 82. Real World Linkedin
  • 83. Real World Linkedin
  • 84. Real World WunderKit
  • 85. Real World Groupon
  • 86. Real World Basecamp
  • 88. Tips & Tricks idAttribute idAttribute: “id” // CouchDB idAttribute: “_id” // .NET idAttribute: “Id”
  • 89. Tips & Tricks Related Models
  • 90. Tips & Tricks Related Models var Invoice = Backbone.Model.extend({ idAttribute: “Id” }); var Invoices = Backbone.Collection.extend({ model: Invoice, url: "/Invoices" });
  • 91. Tips & Tricks Related Models
  • 92. Tips & Tricks Related Models
  • 93. Tips & Tricks Related Models var InvoiceDetail = Backbone.Model.extend({ idAttribute: “Id” }); var InvoiceDetails = Backbone.Collection.extend({ model: InvoiceDetail, url: "/InvoiceDetails“ });
  • 94. Tips & Tricks Related Models var Invoice = Backbone.Model.extend({ idAttribute: "Id", initialize: function () { this.setInvoiceDetails(); }, setInvoiceDetails: function () { this.set({ InvoiceDetails: new InvoiceDetails(this.get("InvoiceDetails")) }); } });
  • 95. Tips & Tricks Related Models
  • 96. Tips & Tricks Related Models
  • 97. Tips & Tricks Related Models var Invoice = Backbone.Model.extend({ idAttribute: "Id", initialize: function () { this.setInvoiceDetails(); this.bind("sync", this.setInvoiceDetails); }, setInvoiceDetails: function () { this.set({ InvoiceDetails: new InvoiceDetails(this.get("InvoiceDetails")) }); } });
  • 99. Extras Plugins • Backbone-Nested • Backbone.Memento • Backbone.Validations • Backbone.localStorage • backbone.couchdb.js • … https://github.com/documentcloud/backbone/wiki/Extensions%2C- Plugins%2C-Resources
  • 100. Extras TDD - Jasmine describe("Todo", function() { it("Should have a title", function() { var todo = new Todo(); expect(todo.get("title")).toBeDefined(); }); });
  • 102. Extras • http://sproutcore.com (Apple/iCloud) • http://knockoutjs.com • http://emberjs.com • http://batmanjs.org (Shopify)
  • 104. Backbone.js + • Lightweight • Powerful • Code is clean (and maintainable) - • Too verbose (for small applications)
  • 105. 3 Lago di Garda Questions ? Grazie www.igloolab.com @iloveigloo