State of the Backbone
blog.documentcloud.org
blog.documentcloud.org
Loving every moments of using it.
I used it once while working with someone else's code, so it's difficult to say, but I like the "less modular" and simpler ways of Backbone.
Unrelatedly, but in case anyone's listening, there's something I keep wanting in Backbone, but perhaps my architecture is wrong:
// inside my view
this.model.on('change', this._onChange, this);
// later
this.model.set({ ... }, null, this);
This example uses a hypothetical version of 'set', which won't trigger 'change' events for any listeners whose context is the third argument. So, my view won't receive a 'change' event after it changes the model.Currently, when my view wants to change something, it modifies the model and then waits to receive the 'change' event before updating what the view actually looks like. However, this feels very indirect and doesn't always work out too well (sometimes I have to resort to setting a 'ignoreNextChangeEvent' variable).
I've had what sounds like a similar situation: I want to display on the view that the model is being updated. In this case, I set a flag on the current view when starting an action, then I watch out for 'sync' events on the model; when the 'sync' message is raised, I perform an action based on the set flags.
Hope that helps.
Edit: Ah beaten to it!
Example: http://stackoverflow.com/questions/9365851/separating-templa...
new View({el: domElement})
... but it's part of Backbone's goals -- which are further explained towards the end of the video -- that a given view has an element at all times, even before any templates may or may not have been rendered.Always having an element means that you can worry less about view state. If all of your DOM events are delegated from the root element, you don't have to worry about whether the template has been rendered yet, which particular template might have been rendered, whether the data is available yet, and so on... The events continue to work regardless.
You don't have to do it if you don't want to. Simplest way to not do it is just implement your custom `render`, and you'll have everything in an empty `div` (the default). If you want your template root to be the element's root (el/$el) as well, you can quite trivially do so by calling View#setElement from View#render:
render: function () {
return this.setElement($(renderTemplate()));
}
There you are, stick that in your parent View class and now you don't "have" to specify anything in your view (which, again, you don't have to anyway).Also, there's no logic in that part, it's just a declarative mapping of your DOM root.
(the caveats of the guy who answered on SO still apply, this will not handle re-rendering as-is and a broken template generating multiple roots will not work correctly)
BB is just so dead straightforward that it really does get out of the way and let's you do things the way you want.