JSDay Italy - Backbone.js

207

description

 

Transcript of JSDay Italy - Backbone.js

Page 1: JSDay Italy - Backbone.js
Page 2: JSDay Italy - Backbone.js
Page 3: JSDay Italy - Backbone.js
Page 4: JSDay Italy - Backbone.js
Page 5: JSDay Italy - Backbone.js
Page 6: JSDay Italy - Backbone.js
Page 7: JSDay Italy - Backbone.js
Page 8: JSDay Italy - Backbone.js
Page 9: JSDay Italy - Backbone.js
Page 10: JSDay Italy - Backbone.js
Page 11: JSDay Italy - Backbone.js
Page 12: JSDay Italy - Backbone.js
Page 13: JSDay Italy - Backbone.js
Page 14: JSDay Italy - Backbone.js
Page 15: JSDay Italy - Backbone.js
Page 16: JSDay Italy - Backbone.js
Page 17: JSDay Italy - Backbone.js
Page 18: JSDay Italy - Backbone.js
Page 19: JSDay Italy - Backbone.js
Page 20: JSDay Italy - Backbone.js
Page 21: JSDay Italy - Backbone.js
Page 22: JSDay Italy - Backbone.js
Page 23: JSDay Italy - Backbone.js
Page 24: JSDay Italy - Backbone.js
Page 25: JSDay Italy - Backbone.js
Page 26: JSDay Italy - Backbone.js
Page 27: JSDay Italy - Backbone.js
Page 28: JSDay Italy - Backbone.js
Page 29: JSDay Italy - Backbone.js
Page 30: JSDay Italy - Backbone.js
Page 31: JSDay Italy - Backbone.js
Page 32: JSDay Italy - Backbone.js
Page 33: JSDay Italy - Backbone.js

var Animal, myAnimal;

Animal = function (name) { this.name = name || 'Unknown';}

Animal.prototype = { say: function () { console.log( 'Hi, my name is ' + this.name + '!' ); }}

myAnimal = new Animal('Bello');myAnimal.say(); // Hi, my name is Bello!

Page 34: JSDay Italy - Backbone.js

var Animal, myAnimal;

Animal = function (name) { this.name = name || 'Unknown';}

Animal.prototype = { say: function () { console.log( 'Hi, my name is ' + this.name + '!' ); }}

myAnimal = new Animal('Bello');myAnimal.say(); // Hi, my name is Bello!

Page 35: JSDay Italy - Backbone.js

var Animal, myAnimal;

Animal = function (name) { this.name = name || 'Unknown';}

Animal.prototype = { say: function () { console.log( 'Hi, my name is ' + this.name + '!' ); }}

myAnimal = new Animal('Bello');myAnimal.say(); // Hi, my name is Bello!

Page 36: JSDay Italy - Backbone.js

var Animal, myAnimal;

Animal = function (name) { this.name = name || 'Unknown';}

Animal.prototype = { say: function () { console.log( 'Hi, my name is ' + this.name + '!' ); }}

myAnimal = new Animal('Bello');myAnimal.say(); // Hi, my name is Bello!

Page 37: JSDay Italy - Backbone.js

var Animal, myAnimal;

Animal = function (name) { this.name = name || 'Unknown';}

Animal.prototype = { say: function () { console.log( 'Hi, my name is ' + this.name + '!' ); }}

myAnimal = new Animal('Bello');myAnimal.say(); // Hi, my name is Bello!

Page 38: JSDay Italy - Backbone.js

var Animal, myAnimal;

Animal = function (name) { this.name = name || 'Unknown';}

Animal.prototype = { say: function () { console.log( 'Hi, my name is ' + this.name + '!' ); }}

myAnimal = new Animal('Bello');myAnimal.say(); // Hi, my name is Bello!

Page 39: JSDay Italy - Backbone.js

var Animal, myAnimal;

Animal = function (name) { this.name = name || 'Unknown';}

Animal.prototype = { say: function () { console.log( 'Hi, my name is ' + this.name + '!' ); }}

myAnimal = new Animal('Bello');myAnimal.say(); // Hi, my name is Bello!

Page 40: JSDay Italy - Backbone.js

var Animal, myAnimal;

Animal = function (name) { this.name = name || 'Unknown';}

Animal.prototype = { say: function () { console.log( 'Hi, my name is ' + this.name + '!' ); }}

myAnimal = new Animal('Bello');myAnimal.say(); // Hi, my name is Bello!

Page 41: JSDay Italy - Backbone.js

var Animal, myAnimal;

Animal = function (name) { this.name = name || 'Unknown';}

Animal.prototype = { say: function () { console.log( 'Hi, my name is ' + this.name + '!' ); }}

myAnimal = new Animal('Bello');myAnimal.say(); // Hi, my name is Bello!

Page 42: JSDay Italy - Backbone.js
Page 43: JSDay Italy - Backbone.js
Page 44: JSDay Italy - Backbone.js

var Animal = Backbone.Model.extend({ say: function () {}});

var Dog = Animal.extend({ bark: function () {}});

Page 45: JSDay Italy - Backbone.js

var Animal = Backbone.Model.extend({ say: function () {}});

var Dog = Animal.extend({ bark: function () {}});

Page 46: JSDay Italy - Backbone.js

var Animal = Backbone.Model.extend({ say: function () {}});

var Dog = Animal.extend({ bark: function () {}});

Page 47: JSDay Italy - Backbone.js

var Animal = Backbone.Model.extend({ say: function () {}});

var Dog = Animal.extend({ bark: function () {}});

Page 48: JSDay Italy - Backbone.js

var Animal = Backbone.Model.extend({ say: function () {}});

var Dog = Animal.extend({ bark: function () {}});

Page 49: JSDay Italy - Backbone.js

var Animal = Backbone.Model.extend({ say: function () {}});

var Dog = Animal.extend({ bark: function () {}});

Page 50: JSDay Italy - Backbone.js

var Dog = Animal.extend({ bark: function () {}});

var myDog = new Dog({ name: 'Bello'});

Page 51: JSDay Italy - Backbone.js

var Dog = Animal.extend({ bark: function () {}});

var myDog = new Dog({ name: 'Bello'});

Page 52: JSDay Italy - Backbone.js

// The self-propagating extend function that Backbone classes use.var extend = function (protoProps, classProps) { var child = inherits(this, protoProps, classProps); child.extend = this.extend; return child;};

// Set up inheritance for the model, collection, and view.Backbone.Model.extend = Backbone.Collection.extend = Backbone.Router.extend = Backbone.View.extend = extend;

Page 53: JSDay Italy - Backbone.js

// The self-propagating extend function that Backbone classes use.var extend = function (protoProps, classProps) { var child = inherits(this, protoProps, classProps); child.extend = this.extend; return child;};

// Set up inheritance for the model, collection, and view.Backbone.Model.extend = Backbone.Collection.extend = Backbone.Router.extend = Backbone.View.extend = extend;

Page 54: JSDay Italy - Backbone.js

// The self-propagating extend function that Backbone classes use.var extend = function (protoProps, classProps) { var child = inherits(this, protoProps, classProps); child.extend = this.extend; return child;};

// Set up inheritance for the model, collection, and view.Backbone.Model.extend = Backbone.Collection.extend = Backbone.Router.extend = Backbone.View.extend = extend;

Page 55: JSDay Italy - Backbone.js

// The self-propagating extend function that Backbone classes use.var extend = function (protoProps, classProps) { var child = inherits(this, protoProps, classProps); child.extend = this.extend; return child;};

// Set up inheritance for the model, collection, and view.Backbone.Model.extend = Backbone.Collection.extend = Backbone.Router.extend = Backbone.View.extend = extend;

Page 56: JSDay Italy - Backbone.js

// The self-propagating extend function that Backbone classes use.var extend = function (protoProps, classProps) { var child = inherits(this, protoProps, classProps); child.extend = this.extend; return child;};

// Set up inheritance for the model, collection, and view.Backbone.Model.extend = Backbone.Collection.extend = Backbone.Router.extend = Backbone.View.extend = extend;

Page 57: JSDay Italy - Backbone.js
Page 58: JSDay Italy - Backbone.js
Page 59: JSDay Italy - Backbone.js
Page 60: JSDay Italy - Backbone.js
Page 61: JSDay Italy - Backbone.js
Page 62: JSDay Italy - Backbone.js
Page 63: JSDay Italy - Backbone.js
Page 64: JSDay Italy - Backbone.js
Page 65: JSDay Italy - Backbone.js
Page 66: JSDay Italy - Backbone.js
Page 67: JSDay Italy - Backbone.js
Page 68: JSDay Italy - Backbone.js
Page 69: JSDay Italy - Backbone.js
Page 70: JSDay Italy - Backbone.js
Page 71: JSDay Italy - Backbone.js
Page 72: JSDay Italy - Backbone.js
Page 73: JSDay Italy - Backbone.js
Page 74: JSDay Italy - Backbone.js
Page 75: JSDay Italy - Backbone.js
Page 76: JSDay Italy - Backbone.js

var AppRouter = Backbone.Router.extend({

routes: { '': 'index', 'q?:query': 'query', 'show/:id': 'show' },

index: function () {}, query: function (queryString) {}, show: function (id) {}

});

Page 77: JSDay Italy - Backbone.js

var AppRouter = Backbone.Router.extend({

routes: { '': 'index', 'q?:query': 'query', 'show/:id': 'show' },

index: function () {}, query: function (queryString) {}, show: function (id) {}

});

Page 78: JSDay Italy - Backbone.js

var AppRouter = Backbone.Router.extend({

routes: { '': 'index', 'q?:query': 'query', 'show/:id': 'show' },

index: function () {}, query: function (queryString) {}, show: function (id) {}

});

Page 79: JSDay Italy - Backbone.js

var AppRouter = Backbone.Router.extend({

routes: { '': 'index', 'q?:query': 'query', 'show/:id': 'show' },

index: function () {}, query: function (queryString) {}, show: function (id) {}

});

Page 80: JSDay Italy - Backbone.js

var AppRouter = Backbone.Router.extend({

routes: { '': 'index', 'q?:query': 'query', 'show/:id': 'show' },

index: function () {}, query: function (queryString) {}, show: function (id) {}

});

Page 81: JSDay Italy - Backbone.js

var AppRouter = Backbone.Router.extend({

routes: { '': 'index', 'q?:query': 'query', 'show/:id': 'show' },

index: function () {}, query: function (queryString) {}, show: function (id) {}

});

Page 82: JSDay Italy - Backbone.js

var AppRouter = Backbone.Router.extend({

routes: { '': 'index', 'q?:query': 'query', 'show/:id': 'show' },

index: function () {}, query: function (queryString) {}, show: function (id) {}

});

Page 83: JSDay Italy - Backbone.js

var AppRouter = Backbone.Router.extend({

routes: { '': 'index', 'q?:query': 'query', 'show/:id': 'show' },

index: function () {}, query: function (queryString) {}, show: function (id) {}

});

Page 84: JSDay Italy - Backbone.js

var AppRouter = Backbone.Router.extend({

routes: { '': 'index', 'q?:query': 'query', 'show/:id': 'show' },

index: function () {}, query: function (queryString) {}, show: function (id) {}

});

Page 85: JSDay Italy - Backbone.js

var AppRouter = Backbone.Router.extend({

routes: { '': 'index', 'q?:query': 'query', 'show/:id': 'show' },

index: function () {}, query: function (queryString) {}, show: function (id) {}

});

Page 86: JSDay Italy - Backbone.js

Backbone.Router.extend({ routes: { /* matches search/pierre/zurich */ 'search/:who/:where': 'serach', /* matches download/avatar/@shvi/large */ 'download/*path': 'download' } search: function (who, where) {}, download: function (path) {}});

Page 87: JSDay Italy - Backbone.js

Backbone.Router.extend({ routes: { /* matches search/pierre/zurich */ 'search/:who/:where': 'serach', /* matches download/avatar/@shvi/large */ 'download/*path': 'download' } search: function (who, where) {}, download: function (path) {}});

Page 88: JSDay Italy - Backbone.js

var AppRouter = Backbone.Router.extend({ // …});new AppRouter();Backbone.history.start();

Page 89: JSDay Italy - Backbone.js

var AppRouter = Backbone.Router.extend({ // …});new AppRouter();Backbone.history.start();

Page 90: JSDay Italy - Backbone.js

var AppRouter = Backbone.Router.extend({ // …});new AppRouter();Backbone.history.start();

Page 93: JSDay Italy - Backbone.js
Page 94: JSDay Italy - Backbone.js
Page 95: JSDay Italy - Backbone.js

var Comment = Backbone.Model.extend({});

var newComment = new Comment({ name: 'Pierre Spring', email: '[email protected]', text: 'Hello World'});

Page 96: JSDay Italy - Backbone.js

var Comment = Backbone.Model.extend({});

var newComment = new Comment({ name: 'Pierre Spring', email: '[email protected]', text: 'Hello World'});

Page 97: JSDay Italy - Backbone.js

var Comment = Backbone.Model.extend({});

var newComment = new Comment({ name: 'Pierre Spring', email: '[email protected]', text: 'Hello World'});

Page 98: JSDay Italy - Backbone.js

var Comment = Backbone.Model.extend({});

var newComment = new Comment({ name: 'Pierre Spring', email: '[email protected]', text: 'Hello World'});

Page 99: JSDay Italy - Backbone.js

var Comment = Backbone.Model.extend({});

var newComment = new Comment({ name: 'Pierre Spring', email: '[email protected]', text: 'Hello World'});

Page 100: JSDay Italy - Backbone.js

var Comment = Backbone.Model.extend({});

var newComment = new Comment({ name: 'Pierre Spring', email: '[email protected]', text: 'Hello World'});

Page 101: JSDay Italy - Backbone.js

var newComment = new Comment({ text: 'Hello World'});

newComment.set({ name: 'Pierre Spring', email: '[email protected]'});

newComment.get('name'); // Pierre Spring

Page 102: JSDay Italy - Backbone.js

var newComment = new Comment({ text: 'Hello World'});

newComment.set({ name: 'Pierre Spring', email: '[email protected]'});

newComment.get('name'); // Pierre Spring

Page 103: JSDay Italy - Backbone.js

var newComment = new Comment({ text: 'Hello World'});

newComment.set({ name: 'Pierre Spring', email: '[email protected]'});

newComment.get('name'); // Pierre Spring

Page 104: JSDay Italy - Backbone.js

var newComment = new Comment({ text: 'Hello World'});

newComment.set({ name: 'Pierre Spring', email: '[email protected]'});

newComment.get('name'); // Pierre Spring

Page 105: JSDay Italy - Backbone.js

var Comment = Backbone.Model.extend({});

var newComment = new Comment({ /* … */ });

newComment.save();

Page 106: JSDay Italy - Backbone.js

var Comment = Backbone.Model.extend({ url: '/api/comment/'});

var newComment = new Comment({ /* … */ });

newComment.save();

Page 107: JSDay Italy - Backbone.js
Page 108: JSDay Italy - Backbone.js

var Comment = Backbone.Model.extend({ localStorage: new Store("comment")});

var newComment = new Comment({ /* … */ });

newComment.save();

Page 109: JSDay Italy - Backbone.js

var Comment = Backbone.Model.extend({ localStorage: new Store("comment"), initialize: function (options) { }});

var newComment = new Comment({ /* … */ });

newComment.save();

Page 110: JSDay Italy - Backbone.js

var Comment = Backbone.Model.extend({ localStorage: new Store("comment"), initialize: function (options) { if (!options.date) { this.set({ date: moment().toString() }); } }});

var newComment = new Comment({ /* … */ });

newComment.save();

Page 111: JSDay Italy - Backbone.js

var Comment = Backbone.Model.extend({ localStorage: new Store("comment"), initialize: function (options) { if (!options.date) { this.set({ date: moment().toString() }); } }});

var newComment = new Comment({ /* … */ });

newComment.save();

Page 112: JSDay Italy - Backbone.js
Page 113: JSDay Italy - Backbone.js

var Comment = Backbone.Model.extend({ localStorage: new Store("comment"), initialize: function (options) { if (!options.date) { this.set({ date: moment().toString() }); } }});

var newComment = new Comment({ /* … */ });

newComment.save();

Page 114: JSDay Italy - Backbone.js

var Comment = Backbone.Model.extend({ localStorage: new Store("comment"), initialize: function (options) { if (!options.date) { this.set({ date: moment().toString() }); } }, getDisplayDate: function () { var d = this.get('date'); return moment(d).fromNow(); }});

Page 115: JSDay Italy - Backbone.js

var Comment = Backbone.Model.extend({ localStorage: new Store("comment"), initialize: function (options) { if (!options.date) { this.set({ date: moment().toString() }); } }, getDisplayDate: function () { var d = this.get('date'); return moment(d).fromNow(); }});

Page 116: JSDay Italy - Backbone.js

var Comment = Backbone.Model.extend({ localStorage: new Store("comment"), initialize: function (options) { if (!options.date) { this.set({ date: moment().toString() }); } }, getDisplayDate: function () { var d = this.get('date'); return moment(d).fromNow(); }});

Page 117: JSDay Italy - Backbone.js

var Comment = Backbone.Model.extend({ localStorage: new Store("comment"), initialize: function (options) { if (!options.date) { this.set({ date: moment().toString() }); } }, getDisplayDate: function () { var d = this.get('date'); return moment(d).fromNow(); }});

Page 118: JSDay Italy - Backbone.js

var newComment = new Comment({ /* … */ });

newComment.getDisplayDate();// a few seconds ago

Page 119: JSDay Italy - Backbone.js

Backbone.Collection.extend({ model: CommentModel, localStorage: new Store("comment")});

Page 120: JSDay Italy - Backbone.js

Backbone.Collection.extend({ model: CommentModel, localStorage: new Store("comment")});

Page 121: JSDay Italy - Backbone.js

Backbone.Collection.extend({ model: CommentModel, localStorage: new Store("comment")});

Page 122: JSDay Italy - Backbone.js

Backbone.Collection.extend({ model: CommentModel, localStorage: new Store("comment")});

Page 123: JSDay Italy - Backbone.js

Backbone.Collection.extend({ model: CommentModel, localStorage: new Store("comment")});

Page 124: JSDay Italy - Backbone.js

var CommentCollection = Backbone.Collection.extend({ /* … */});

var commentCollection = new CommentCollection();

commentCollection.fetch();

commentCollection.each(function (commentModel) { // do s.th.});

Page 125: JSDay Italy - Backbone.js

var CommentCollection = Backbone.Collection.extend({ /* … */});

var commentCollection = new CommentCollection();

commentCollection.fetch();

commentCollection.each(function (commentModel) { // do s.th.});

Page 126: JSDay Italy - Backbone.js

var CommentCollection = Backbone.Collection.extend({ /* … */});

var commentCollection = new CommentCollection();

commentCollection.fetch();

commentCollection.each(function (commentModel) { // do s.th.});

Page 127: JSDay Italy - Backbone.js

var CommentCollection = Backbone.Collection.extend({ /* … */});

var commentCollection = new CommentCollection();

commentCollection.fetch();

commentCollection.each(function (commentModel) { // do s.th.});

Page 128: JSDay Italy - Backbone.js
Page 129: JSDay Italy - Backbone.js

var CommentCollection = Backbone.Collection.extend({ /* … */});

var commentCollection = new CommentCollection();

commentCollection.fetch();

commentCollection.each(function (commentModel) { // do s.th.});

Page 130: JSDay Italy - Backbone.js

var newComment = new Comment({ /* … */ });newComment.save();commentCollection.add(newComment);

Page 131: JSDay Italy - Backbone.js

var newComment = new Comment({ /* … */ });newComment.save();commentCollection.add(newComment);

Page 132: JSDay Italy - Backbone.js

var newComment = new Comment({ /* … */ });newComment.save();commentCollection.add(newComment);

Page 133: JSDay Italy - Backbone.js

var newComment = new Comment({ /* … */ });newComment.save();commentCollection.add(newComment);

Page 134: JSDay Italy - Backbone.js

var newComment = new Comment({ /* … */ });newComment.save();commentCollection.add(newComment);

var newComment = commentCollection.create({ /* model attributes */});

Page 135: JSDay Italy - Backbone.js

newComment.bind( 'change', function (model) {});newComment.bind( 'change:name', function (model, attribute) {});commentCollection.bind( 'reset', function (commentCollection) {});commentCollection.bind( 'add', function (commentModel) {});

Page 136: JSDay Italy - Backbone.js

newComment.bind( 'change', function (model) {});newComment.bind( 'change:name', function (model, attribute) {});commentCollection.bind( 'reset', function (commentCollection) {});commentCollection.bind( 'add', function (commentModel) {});

Page 137: JSDay Italy - Backbone.js

newComment.bind( 'change', function (model) {});newComment.bind( 'change:name', function (model, attribute) {});commentCollection.bind( 'reset', function (commentCollection) {});commentCollection.bind( 'add', function (commentModel) {});

Page 138: JSDay Italy - Backbone.js

newComment.bind( 'change', function (model) {});newComment.bind( 'change:name', function (model, attribute) {});commentCollection.bind( 'reset', function (commentCollection) {});commentCollection.bind( 'add', function (commentModel) {});

Page 139: JSDay Italy - Backbone.js

newComment.bind( 'change', function (model) {});newComment.bind( 'change:name', function (model, attribute) {});commentCollection.bind( 'reset', function (commentCollection) {});commentCollection.bind( 'add', function (commentModel) {});

Page 140: JSDay Italy - Backbone.js

newComment.bind( 'change', function (model) {});newComment.bind( 'change:name', function (model, attribute) {});commentCollection.bind( 'reset', function (commentCollection) {});commentCollection.bind( 'add', function (commentModel) {});

Page 141: JSDay Italy - Backbone.js

newComment.bind( 'change', function (model) {});newComment.bind( 'change:name', function (model, attribute) {});commentCollection.bind( 'reset', function (commentCollection) {});commentCollection.bind( 'add', function (commentModel) {});

Page 142: JSDay Italy - Backbone.js

newComment.bind( 'change', function (model) {});newComment.bind( 'change:name', function (model, attribute) {});commentCollection.bind( 'reset', function (commentCollection) {});commentCollection.bind( 'add', function (commentModel) {});

Page 143: JSDay Italy - Backbone.js

newComment.bind( 'change', function (model) {});newComment.bind( 'change:name', function (model, attribute) {});commentCollection.bind( 'reset', function (commentCollection) {});commentCollection.bind( 'add', function (commentModel) {});

Page 144: JSDay Italy - Backbone.js

newComment.bind( 'change', function (model) {});newComment.bind( 'change:name', function (model, attribute) {});commentCollection.bind( 'reset', function (commentCollection) {});commentCollection.bind( 'add', function (commentModel) {});

Page 145: JSDay Italy - Backbone.js

newComment.bind( 'change', function (model) {});newComment.bind( 'change:name', function (model, attribute) {});commentCollection.bind( 'reset', function (commentCollection) {});commentCollection.bind( 'add', function (commentModel) {});

Page 146: JSDay Italy - Backbone.js
Page 147: JSDay Italy - Backbone.js

var CommentView = Backbone.View.extend({});var commentView = new CommentView();console.log(commentView.el);// <div></div>

Page 148: JSDay Italy - Backbone.js

var CommentView = Backbone.View.extend({});var commentView = new CommentView();console.log(commentView.el);// <div></div>

Page 149: JSDay Italy - Backbone.js

var CommentView = Backbone.View.extend({});var commentView = new CommentView();console.log(commentView.el);// <div></div>

Page 150: JSDay Italy - Backbone.js

var CommentView = Backbone.View.extend({});var commentView = new CommentView();console.log(commentView.el);// <div></div>

Page 151: JSDay Italy - Backbone.js

var CommentView = Backbone.View.extend({});var commentView = new CommentView();console.log(commentView.el);// <div></div>

Page 152: JSDay Italy - Backbone.js

var CommentView = Backbone.View.extend({ tagName: 'p', className: 'comment-list', id: 'container',});var commentView = new CommentView();console.log(commentView.el);// <p id= "container" class= "comment-list"/>

Page 153: JSDay Italy - Backbone.js

var CommentView = Backbone.View.extend({ tagName: 'p', className: 'comment-list', id: 'container',});var commentView = new CommentView();console.log(commentView.el);// <p id= "container" class= "comment-list"/>

Page 154: JSDay Italy - Backbone.js

var CommentView = Backbone.View.extend({ tagName: 'p', className: 'comment-list', id: 'container',});var commentView = new CommentView();console.log(commentView.el);// <p id= "container" class= "comment-list"/>

Page 155: JSDay Italy - Backbone.js

var CommentView = Backbone.View.extend({ tagName: 'p', className: 'comment-list', id: 'container',});var commentView = new CommentView();console.log(commentView.el);// <p id= "container" class= "comment-list"/>

Page 156: JSDay Italy - Backbone.js

var CommentView = Backbone.View.extend({ el: $('#comment-list')});var commentView = new CommentView();console.log(commentView.el);

Page 157: JSDay Italy - Backbone.js

var CommentView = Backbone.View.extend({ initialize: function (options) { this.listRowTemplate = _.template($('#listRowTemplate').html()); options.commentCollection.bind('reset', this.renderRows, this); options.commentCollection.bind('add', this.renderRow, this); },

renderRows: function (commentCollection) { commentCollection.each(function (commentModel) { this.renderRow(commentModel); }, this); },

renderRow: function (commentModel) { $(this.el).prepend( this.listRowTemplate({ comment: commentModel.toJSON() }) ); }});

Page 158: JSDay Italy - Backbone.js

var CommentView = Backbone.View.extend({ initialize: function (options) { this.listRowTemplate = _.template($('#listRowTemplate').html()); options.commentCollection.bind('reset', this.renderRows, this); options.commentCollection.bind('add', this.renderRow, this); },

renderRows: function (commentCollection) { commentCollection.each(function (commentModel) { this.renderRow(commentModel); }, this); },

renderRow: function (commentModel) { $(this.el).prepend( this.listRowTemplate({ comment: commentModel.toJSON() }) ); }});

Page 159: JSDay Italy - Backbone.js

var CommentView = Backbone.View.extend({ initialize: function (options) { this.listRowTemplate = _.template($('#listRowTemplate').html()); options.commentCollection.bind('reset', this.renderRows, this); options.commentCollection.bind('add', this.renderRow, this); },

renderRows: function (commentCollection) { commentCollection.each(function (commentModel) { this.renderRow(commentModel); }, this); },

renderRow: function (commentModel) { $(this.el).prepend( this.listRowTemplate({ comment: commentModel.toJSON() }) ); }});

Page 160: JSDay Italy - Backbone.js

var CommentView = Backbone.View.extend({ initialize: function (options) { this.listRowTemplate = _.template($('#listRowTemplate').html()); options.commentCollection.bind('reset', this.renderRows, this); options.commentCollection.bind('add', this.renderRow, this); },

renderRows: function (commentCollection) { commentCollection.each(function (commentModel) { this.renderRow(commentModel); }, this); },

renderRow: function (commentModel) { $(this.el).prepend( this.listRowTemplate({ comment: commentModel.toJSON() }) ); }});

Page 161: JSDay Italy - Backbone.js

var CommentView = Backbone.View.extend({ initialize: function (options) { this.listRowTemplate = _.template($('#listRowTemplate').html()); options.commentCollection.bind('reset', this.renderRows, this); options.commentCollection.bind('add', this.renderRow, this); },

renderRows: function (commentCollection) { commentCollection.each(function (commentModel) { this.renderRow(commentModel); }, this); },

renderRow: function (commentModel) { $(this.el).prepend( this.listRowTemplate({ comment: commentModel.toJSON() }) ); }});

Page 162: JSDay Italy - Backbone.js

var CommentView = Backbone.View.extend({ initialize: function (options) { this.listRowTemplate = _.template($('#listRowTemplate').html()); options.commentCollection.bind('reset', this.renderRows, this); options.commentCollection.bind('add', this.renderRow, this); },

renderRows: function (commentCollection) { commentCollection.each(function (commentModel) { this.renderRow(commentModel); }, this); },

renderRow: function (commentModel) { $(this.el).prepend( this.listRowTemplate({ comment: commentModel.toJSON() }) ); }});

Page 163: JSDay Italy - Backbone.js

var CommentView = Backbone.View.extend({ initialize: function (options) { this.listRowTemplate = _.template($('#listRowTemplate').html()); options.commentCollection.bind('reset', this.renderRows, this); options.commentCollection.bind('add', this.renderRow, this); },

renderRows: function (commentCollection) { commentCollection.each(function (commentModel) { this.renderRow(commentModel); }, this); },

renderRow: function (commentModel) { $(this.el).prepend( this.listRowTemplate({ comment: commentModel.toJSON() }) ); }});

Page 164: JSDay Italy - Backbone.js

var CommentView = Backbone.View.extend({ initialize: function (options) { this.listRowTemplate = _.template($('#listRowTemplate').html()); options.commentCollection.bind('reset', this.renderRows, this); options.commentCollection.bind('add', this.renderRow, this); },

renderRows: function (commentCollection) { commentCollection.each(function (commentModel) { this.renderRow(commentModel); }, this); },

renderRow: function (commentModel) { $(this.el).prepend( this.listRowTemplate({ comment: commentModel.toJSON() }) ); }});

Page 165: JSDay Italy - Backbone.js

var commentCollection = new commentCollection();

var commentView = new CommentView({ commentCollection: commentCollection});

Page 166: JSDay Italy - Backbone.js

var commentCollection = new commentCollection();

var commentView = new CommentView({ commentCollection: commentCollection});

Page 167: JSDay Italy - Backbone.js

var CommentView = Backbone.View.extend({ initialize: function (options) { this.listRowTemplate = _.template($('#listRowTemplate').html()); options.commentCollection.bind('reset', this.renderRows, this); options.commentCollection.bind('add', this.renderRow, this); },

renderRows: function (commentCollection) { commentCollection.each(function (commentModel) { this.renderRow(commentModel); }, this); },

renderRow: function (commentModel) { $(this.el).prepend( this.listRowTemplate({ comment: commentModel.toJSON() }) ); }});

Page 168: JSDay Italy - Backbone.js

var CommentView = Backbone.View.extend({ initialize: function (options) { this.listRowTemplate = _.template($('#listRowTemplate').html()); options.commentCollection.bind('reset', this.renderRows, this); options.commentCollection.bind('add', this.renderRow, this); },

renderRows: function (commentCollection) { commentCollection.each(function (commentModel) { this.renderRow(commentModel); }, this); },

renderRow: function (commentModel) { $(this.el).prepend( this.listRowTemplate({ comment: commentModel.toJSON() }) ); }});

Page 169: JSDay Italy - Backbone.js

var CommentView = Backbone.View.extend({ initialize: function (options) { this.listRowTemplate = _.template($('#listRowTemplate').html()); options.commentCollection.bind('reset', this.renderRows, this); options.commentCollection.bind('add', this.renderRow, this); },

renderRows: function (commentCollection) { commentCollection.each(function (commentModel) { this.renderRow(commentModel); }, this); },

renderRow: function (commentModel) { $(this.el).prepend( this.listRowTemplate({ comment: commentModel.toJSON() }) ); }});

Page 170: JSDay Italy - Backbone.js

var CommentView = Backbone.View.extend({ initialize: function (options) { this.listRowTemplate = _.template($('#listRowTemplate').html()); options.commentCollection.bind('reset', this.renderRows, this); options.commentCollection.bind('add', this.renderRow, this); },

renderRows: function (commentCollection) { commentCollection.each(function (commentModel) { this.renderRow(commentModel); }, this); },

renderRow: function (commentModel) { $(this.el).prepend( this.listRowTemplate({ comment: commentModel.toJSON() }) ); }});

Page 171: JSDay Italy - Backbone.js

var CommentView = Backbone.View.extend({ initialize: function (options) { this.listRowTemplate = _.template($('#listRowTemplate').html()); options.commentCollection.bind('reset', this.renderRows, this); options.commentCollection.bind('add', this.renderRow, this); },

renderRows: function (commentCollection) { commentCollection.each(function (commentModel) { this.renderRow(commentModel); }, this); },

renderRow: function (commentModel) { $(this.el).prepend( this.listRowTemplate({ comment: commentModel.toJSON() }) ); }});

Page 172: JSDay Italy - Backbone.js

var CommentView = Backbone.View.extend({ initialize: function (options) { this.listRowTemplate = _.template($('#listRowTemplate').html()); options.commentCollection.bind('reset', this.renderRows, this); options.commentCollection.bind('add', this.renderRow, this); },

renderRows: function (commentCollection) { commentCollection.each(function (commentModel) { this.renderRow(commentModel); }, this); },

renderRow: function (commentModel) { $(this.el).prepend( this.listRowTemplate({ comment: commentModel.toJSON() }) ); }});

Page 173: JSDay Italy - Backbone.js

var CommentView = Backbone.View.extend({ initialize: function (options) { this.listRowTemplate = _.template($('#listRowTemplate').html()); options.commentCollection.bind('reset', this.renderRows, this); options.commentCollection.bind('add', this.renderRow, this); },

renderRows: function (commentCollection) { commentCollection.each(function (commentModel) { this.renderRow(commentModel); }, this); },

renderRow: function (commentModel) { $(this.el).prepend( this.listRowTemplate({ comment: commentModel.toJSON() }) ); }});

Page 174: JSDay Italy - Backbone.js

var CommentView = Backbone.View.extend({ initialize: function (options) { this.listRowTemplate = _.template($('#listRowTemplate').html()); options.commentCollection.bind('reset', this.renderRows, this); options.commentCollection.bind('add', this.renderRow, this); },

renderRows: function (commentCollection) { commentCollection.each(function (commentModel) { this.renderRow(commentModel); }, this); },

renderRow: function (commentModel) { $(this.el).prepend( this.listRowTemplate({ comment: commentModel.toJSON() }) ); }});

Page 175: JSDay Italy - Backbone.js

var CommentView = Backbone.View.extend({ initialize: function (options) { this.listRowTemplate = _.template($('#listRowTemplate').html()); options.commentCollection.bind('reset', this.renderRows, this); options.commentCollection.bind('add', this.renderRow, this); },

renderRows: function (commentCollection) { commentCollection.each(function (commentModel) { this.renderRow(commentModel); }, this); },

renderRow: function (commentModel) { $(this.el).prepend( this.listRowTemplate({ comment: commentModel.toJSON() }) ); }});

Page 176: JSDay Italy - Backbone.js

var CommentView = Backbone.View.extend({ initialize: function (options) { this.listRowTemplate = _.template($('#listRowTemplate').html()); options.commentCollection.bind('reset', this.renderRows, this); options.commentCollection.bind('add', this.renderRow, this); },

renderRows: function (commentCollection) { commentCollection.each(function (commentModel) { this.renderRow(commentModel); }, this); },

renderRow: function (commentModel) { $(this.el).prepend( this.listRowTemplate({ comment: commentModel.toJSON() }) ); }});

Page 177: JSDay Italy - Backbone.js

var CommentView = Backbone.View.extend({ initialize: function (options) { this.listRowTemplate = _.template($('#listRowTemplate').html()); options.commentCollection.bind('reset', this.renderRows, this); options.commentCollection.bind('add', this.renderRow, this); },

renderRows: function (commentCollection) { commentCollection.each(function (commentModel) { this.renderRow(commentModel); }, this); },

renderRow: function (commentModel) { $(this.el).prepend( this.listRowTemplate({ comment: commentModel.toJSON() }) ); }});

Page 178: JSDay Italy - Backbone.js

var CommentView = Backbone.View.extend({ initialize: function (options) { this.listRowTemplate = _.template($('#listRowTemplate').html()); options.commentCollection.bind('reset', this.renderRows, this); options.commentCollection.bind('add', this.renderRow, this); },

renderRows: function (commentCollection) { commentCollection.each(function (commentModel) { this.renderRow(commentModel); }, this); },

renderRow: function (commentModel) { $(this.el).prepend( this.listRowTemplate({ comment: commentModel.toJSON() }) ); }});

Page 179: JSDay Italy - Backbone.js

var CommentView = Backbone.View.extend({ initialize: function (options) { this.listRowTemplate = _.template($('#listRowTemplate').html()); options.commentCollection.bind('reset', this.renderRows, this); options.commentCollection.bind('add', this.renderRow, this); },

renderRows: function (commentCollection) { commentCollection.each(function (commentModel) { this.renderRow(commentModel); }, this); },

renderRow: function (commentModel) { $(this.el).prepend( this.listRowTemplate({ comment: commentModel.toJSON() }) ); }});

Page 180: JSDay Italy - Backbone.js

var CommentView = Backbone.View.extend({ initialize: function (options) { this.listRowTemplate = _.template($('#listRowTemplate').html()); options.commentCollection.bind('reset', this.renderRows, this); options.commentCollection.bind('add', this.renderRow, this); },

renderRows: function (commentCollection) { commentCollection.each(function (commentModel) { this.renderRow(commentModel); }, this); },

renderRow: function (commentModel) { $(this.el).prepend( this.listRowTemplate({ comment: commentModel.toJSON() }) ); }});

Page 181: JSDay Italy - Backbone.js

var commentCollection = new commentCollection();

var commentView = new CommentView({ commentCollection: commentCollection});

$('.list-view').html(commentView.el);

commentCollection.fetch();

Page 182: JSDay Italy - Backbone.js

var commentCollection = new commentCollection();

var commentView = new CommentView({ commentCollection: commentCollection});

$('.list-view').html(commentView.el);

commentCollection.fetch();

Page 183: JSDay Italy - Backbone.js

var commentCollection = new commentCollection();

var commentView = new CommentView({ commentCollection: commentCollection});

$('.list-view').html(commentView.el);

commentCollection.fetch();

Page 184: JSDay Italy - Backbone.js

var commentCollection = new commentCollection();

var commentView = new CommentView({ commentCollection: commentCollection});

$('.list-view').html(commentView.el);

commentCollection.fetch();

Page 185: JSDay Italy - Backbone.js

var CommentFormView = Backbone.View.extend({ events: { 'submit form': 'newComment' }, initialize: function (options) { /* … */ }, render: function () { /* … */ },

newComment: function (e) { var options, comment; e.preventDefault();

options = {}; _.each( this.$('form').serializeArray(), function (field) { options[field.name] = field.value; } );

this.commentCollection.create(options);

this.$('input, textarea').val(''); }});

Page 186: JSDay Italy - Backbone.js

var CommentFormView = Backbone.View.extend({ events: { 'submit form': 'newComment' }, initialize: function (options) { /* … */ }, render: function () { /* … */ },

newComment: function (e) { var options, comment; e.preventDefault();

options = {}; _.each( this.$('form').serializeArray(), function (field) { options[field.name] = field.value; } );

this.commentCollection.create(options);

this.$('input, textarea').val(''); }});

Page 187: JSDay Italy - Backbone.js

var CommentFormView = Backbone.View.extend({ events: { 'submit form': 'newComment' }, initialize: function (options) { /* … */ }, render: function () { /* … */ },

newComment: function (e) { var options, comment; e.preventDefault();

options = {}; _.each( this.$('form').serializeArray(), function (field) { options[field.name] = field.value; } );

this.commentCollection.create(options);

this.$('input, textarea').val(''); }});

Page 188: JSDay Italy - Backbone.js

var CommentFormView = Backbone.View.extend({ events: { 'submit form': 'newComment' }, initialize: function (options) { /* … */ }, render: function () { /* … */ },

newComment: function (e) { var options, comment; e.preventDefault();

options = {}; _.each( this.$('form').serializeArray(), function (field) { options[field.name] = field.value; } );

this.commentCollection.create(options);

this.$('input, textarea').val(''); }});

Page 189: JSDay Italy - Backbone.js

var CommentFormView = Backbone.View.extend({ events: { 'submit form': 'newComment' }, initialize: function (options) { /* … */ }, render: function () { /* … */ },

newComment: function (e) { var options, comment; e.preventDefault();

options = {}; _.each( this.$('form').serializeArray(), function (field) { options[field.name] = field.value; } );

this.commentCollection.create(options);

this.$('input, textarea').val(''); }});

Page 190: JSDay Italy - Backbone.js

var CommentFormView = Backbone.View.extend({ events: { 'submit form': 'newComment' }, initialize: function (options) { /* … */ }, render: function () { /* … */ },

newComment: function (e) { var options, comment; e.preventDefault();

options = {}; _.each( this.$('form').serializeArray(), function (field) { options[field.name] = field.value; } );

this.commentCollection.create(options);

this.$('input, textarea').val(''); }});

Page 191: JSDay Italy - Backbone.js

var CommentFormView = Backbone.View.extend({ events: { 'submit form': 'newComment' }, initialize: function (options) { /* … */ }, render: function () { /* … */ },

newComment: function (e) { var options, comment; e.preventDefault();

options = {}; _.each( this.$('form').serializeArray(), function (field) { options[field.name] = field.value; } );

this.commentCollection.create(options);

this.$('input, textarea').val(''); }});

Page 192: JSDay Italy - Backbone.js

var CommentFormView = Backbone.View.extend({ events: { 'submit form': 'newComment' }, initialize: function (options) { /* … */ }, render: function () { /* … */ },

newComment: function (e) { var options, comment; e.preventDefault();

options = {}; _.each( this.$('form').serializeArray(), function (field) { options[field.name] = field.value; } );

this.commentCollection.create(options);

this.$('input, textarea').val(''); }});

Page 193: JSDay Italy - Backbone.js

var CommentFormView = Backbone.View.extend({ events: { 'submit form': 'newComment' }, initialize: function (options) { /* … */ }, render: function () { /* … */ },

newComment: function (e) { var options, comment; e.preventDefault();

options = {}; _.each( this.$('form').serializeArray(), function (field) { options[field.name] = field.value; } );

this.commentCollection.create(options);

this.$('input, textarea').val(''); }});

Page 194: JSDay Italy - Backbone.js

var CommentFormView = Backbone.View.extend({ events: { 'submit form': 'newComment' }, initialize: function (options) { /* … */ }, render: function () { /* … */ },

newComment: function (e) { var options, comment; e.preventDefault();

options = {}; _.each( this.$('form').serializeArray(), function (field) { options[field.name] = field.value; } );

this.commentCollection.create(options);

this.$('input, textarea').val(''); }});

Page 195: JSDay Italy - Backbone.js
Page 196: JSDay Italy - Backbone.js
Page 197: JSDay Italy - Backbone.js
Page 199: JSDay Italy - Backbone.js
Page 200: JSDay Italy - Backbone.js
Page 201: JSDay Italy - Backbone.js
Page 202: JSDay Italy - Backbone.js
Page 203: JSDay Italy - Backbone.js
Page 204: JSDay Italy - Backbone.js
Page 205: JSDay Italy - Backbone.js
Page 206: JSDay Italy - Backbone.js
Page 207: JSDay Italy - Backbone.js