The document discusses a presentation on client-side MVC with Backbone.js. It includes an agenda that covers why Backbone.js, its architecture including models, collections, views, templates and routers, real world examples, tips and tricks, and extras. The architecture section describes how Backbone.js provides structure using models, collections, views and connecting to RESTful APIs. It also outlines the MVC components and their roles.
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.
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.
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
100. Extras
TDD - Jasmine
describe("Todo", function() {
it("Should have a title", function() {
var todo = new Todo();
expect(todo.get("title")).toBeDefined();
});
});