- collection.fetch() now correctly calls model.parse() (I patched Backbone.Collection.prototype.parse(), but their fix is nicer)
- 'add' and 'remove' events now include the index (I had to work it out from scratch with sortedIndex())
- event 'bind' is now called 'on' (sensible as _.bind is already used for partial application)
- confusion over this.el and $()-wrapping is now cleared up
- events hash can now include functions (I like to avoid reflection where possible - even in JS)
- collection.create() now fires 'add' before the server replies (this makes writing a responsive UI much easier)
The last one is quite a significant change! Luckily my app is easy to fix, as I've only spent a few days on it.
I've added the corresponding documentation, and added it to the change log for 0.9 as well.
book.on("change:title change:author", function() {
...
});What is the recommended method for dealing with the optimistic model events? If my view gets the "destroy" event but the sync fails, do I have to parse the response on the "error" event to figure out that it corresponds to the destroy action?
It might be nice to have e.g. "destroy:failed" for the benefit of views that send off these requests and want to un-change the UI and show errors if they fail.
Note that you'll also now get the new "sync" event, after the model has been successfully deleted on the server.
Few questions though,
1. Would you consider adding computed properties to models and collections?
2. I have a bindModel and close methods to all my views so that close() unbinds all the methods in the views that were bound to the models/collections and it also unbinds the view events. Any reason why such a mechanism is not embedded out of the box in backbone? Or am I missing something?
https://github.com/documentcloud/documentcloud/blob/master/p... ... and so on.
2. Not all views display a single model -- some views show data from several, some views display an entire collection, and some views don't have any models attached. Additionally, if you tend to throw away your views at the same time you throw away your models (we tend to do this), you'll never have to unbind anything, as both are GC'd together.
It's only the case that if you tend to remove views but leave their models around to be rendered by other views later, then you need this sort of thing. And if that's the case for your app, then by all means, adding a `close()` function or the equivalent is a great idea.
2. The way I get around the problem is that bindModel takes (model, eventName, func, context) so having a view that represent different models isn't an issue in this case because it ends up being passed to bindModel.
example:
initialize: function () {
this.bindModel(this.model.get('someCollection'), 'add', someFunc, this);
}In the app I am working on, my models tend to live much longer than the views, and they usually get updates from the server.
2. Good Question.
http://backbonejs.org/#upgrading
Really, in the little over a year since the initial Backbone.js code drop, it's been incredible to see how many amazing apps have been built with it, a sentiment expressed concisely on Twitter this morning:
https://twitter.com/#!/donnierayjones/status/164012817584881...
Cheers!