HTML and CSS Reference
In-Depth Information
Figure 4-11. Backbone github stats, June 2012
With Backbone, you represent your data as models , which can be created, validated,
destroyed, and saved to the server. Whenever a UI action causes an attribute of a model
to change, the model triggers a change event; all the views that display the model's state
can be notified of the change so that they are able to respond accordingly, rerendering
themselves with the new information. In a finished Backbone app, you don't have to
write the glue code that looks into the DOM to find an element with a specific ID and
update the HTML manually. When the model changes, the views simply update them‐
selves.
In the end, Backbone is better suited for larger frameworks and applications. If you are
writing a simple application that needs the structure of MVC, you will end up writing
a lot of code to present a simple interface.
Each framework discussion gives a demo hosted in this topic's github
repository. For Backbone, you can find the following RESTful demo
written in Java at https://github.com/html5e/backbone-jax-cellar .
Backbone server synchronization
If your backend data is exposed through a pure RESTful API, retrieving ( GET ), creating
( POST ), updating ( PUT ), and deleting ( DELETE ) models is incredibly easy using the Back‐
bone.js simple Model API. For example:
// Models
window . Book = Backbone . Model . extend ({
urlRoot : "/api/books" ,
defaults : {
"id" : null ,
"name" : "HTML5 Architecture" ,
}
});
window . BookCollection = Backbone . Collection . extend ({
model : Book ,
url : "/api/books"
});
 
Search WWH ::




Custom Search