I, for one, can't wait to use Backbone.js again and put these experiences to practise.As we wrap up the “quick introductions” part of our Introduction to web and mobile development series, here I'll be presenting Backbone.js - a JavaScript framework that plays nicely with jQuery and Ruby on Rails. While it can be argued that its documentation isn't always clear enough about the intended uses of the models, router and views, there is plenty of information available to help you along the right path for your application. Conclusionīackbone.js is a great framework to use when your client-side JavaScript is reaching that icky-spaghetti-with-mudball-sauce-point. url function and/or routes can do the trick, but you're better off sticking to Backbone's suggestion (and good REST design in general). If your REST design does not quite match, then a combination of the model's. sync function and in this post, Backbone.js works well with REST, especially when the interface is designed properly around the use of nouns, id's and the standard CRUD operations used on them. Keep Backbone.js in mind when designing your REST interfaceĪs documented in its. This excellent article by Derick Bailey helped to understand Backbone's function. The intended flow of control should go from the views event handler to the model and back to the view via the views event listener. If for some reason you need to manually direct the router to another url this should only be because there is a need to have this url in your browser's history, and almost never just to simulate a user's action taken by clicking. The other is to add url's to your browser's history for better navigation. One is allowing a URL to be directly accessible from outside your site. The Router has two main functions in Backbone.js. This might put your model and view in an inconsistent state, and why should you execute scripts from your template when you can bind events to any object with Backbone.js? Don't manipulate the router If you don't stay in this backbone-centric mindset you might start to include small pieces of page-specific script in your templates that your model does not know about. Communication between views can be done using an event aggregator. Instead, all actions should have appropriate events that alter the state of the model, which then takes care of updating the view(s). Views should not alter themselves or reference other views. A popular view on Backbone.js is that its applications should be event-driven. This means that everything your application does is done through Backbone.js. Probably the most important thing to remember is that Backbone.js is client-side MVC/MVP framework and you should use it as such. If you are new to Backbone.js (and the underlying Underscore.js), then Addy Osmani's book-in-progress is a great place to start. We gained this experience through our mistakes, and while there are already a number of articles online about the strengths, weaknesses and pitfalls of Backbone.js that I will include below, another article hopefully means good advice to those new to Backbone.js and a nudge in the right direction. No matter how good the example material is, it's no substitute for actual experience. Backbone.js is very much the vogue right now and since we already had an internal toy project that used Backbone.js we expected no big problems.īut of course we faced problems. For a recent project we decided to use Backbone.js to provide structure to the client side of our RESTful Web application.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |