BACKBONE MODELS Make a model subclass using .extend( ) var
Property
=
Backbone.Model.extend({
star:
function()
{
this.set("starred",
!this.get("starred"));
this.save();
}
});
(code in this presentation is from the book, & final versions of sample apps are @ github.com/pselle/choosing-javascript-framework)
BACKBONE VIEWS Using a view with a model var
myHouse
=
new
Property({
location:
"middle
of
our
street",
noiseLevel:
"usually
quite
loud"
});
var
propertyView
=
new
PropertyView({
model:
myHouse
});
propertyView.render()
document.body.appendChild(propertyView.el);
OTHER COMPONENTS • Collections • Groups of models • Router • Read/write the URL without reloading the page • Events • Views trigger updates to model, vice versa • Core component of Backbone
WHAT YOU GET • Strongly defined building components (directives, controllers, services) • Two-way data binding • Dependency injection • Auxiliary tools available: Karma, Protractor
WEAKNESSES • Recent rise to prominence = less time in prod • High lock-in with writing behavior in markup • Skeptics for future roadmap/Google backing • 1.3 drops IE8 support, some teams stuck in older version now (abandonware fears)
WHAT YOU GET • Very strongly defined MVC components • Two-way data binding • Ember Components (like directives) • Great routing support • Dependency injection
WEAKNESSES • Sometimes TOO much information • “Right” way to do things = difficult to get up to speed quickly • Lots of rules • Not as pervasive as other two major frameworks
CONTROLLERS Decorate a model with display logic App.IndexController
=
Ember.ArrayController.extend({
queryParams:
['sortAscending'],
sortProperties:
['price']
});
EVALUATION TOOLS • Spreadsheet for ranking: http://bit.ly/1g6kDSS • Rank frameworks according to business, technical, and team criteria • Wharton DevTap: http://technology.wharton.upenn.edu/devtap/