5 ms·
Backbone.js 0.9.9 Released
- deleted 14y ago[deleted]
- jashkenas 14y agoThis is an "almost-1.0" preview release -- so if you've got a Backbone app, I'd appreciate it if you'd take the time to upgrade, and report issues and concerns. Some of the more significant updates are: * `listenTo` and `stopListening` for easier event unbinding. * HTTP PATCH support, for partial updates. * collection.update(models) for "smart" add/remove/merge in one method. * Events.once, a-la jQuery. Also jQuery-style event map syntax. * Lots of performance tuning for triggering millions of events per second (should you find the need) in modern browsers. http://jsperf.com/events-vs-events2/3
- mcrider 14y agoThanks for your hard work as always!
- danso 14y agoIs the tentative goal to have 1.0 out before we ring in the new year?
- jashkenas 14y agoShhh ... you'll ruin the surprise ;)
- drewda 14y agoIs that first bullet point a solution to view "garbage collection"? Or should those of us who want that sort of functionality continue to use extra helper code?
- tgriesser 14y agoYes - view.remove() calls "stopListening" - so when you use "listenTo" all listeners should be taken care of. This doesn't account for any child-views, or views that don't use .remove(), so you'll need to make sure those are taken care of when a view is destroyed. But in most cases, the garbage collection issues that have been seen relating to views & events are taken care of.
- jashkenas 14y agoSomewhat. The usual rules of working in a garbage collected language still apply -- references are references, and keeping an event bound to another object is a reference to that object. `listenTo` and `stopListening` just give you an inverted (and often easier) way to manage the references ... so that you can remove all of the references from the "other" side. For example: view.listenTo(model, 'change', view.renderChange); view.listenTo(collection, 'add', view.addItem); view.listenTo(Backbone, 'initialLoad', view.reinit); # ... and then, when you want to get rid of the view: view.remove(); # Calls view.stopListening(), removing *all* of the # events from "view" bound on all of those different objects. Note that none of this is necessary if you throw away both sides of the bound event at the same time -- those will still be GC'd as usual. Also, this isn't just for Views. The methods are available on anything that mixes in Backbone.Events.
- drewda 14y agoThanks for the explanation. Looks like a useful and nicely minimal addition.
- eric-hu 14y agoA comment on the description of listenTo on the Docs page: > Tell an object to listen to a particular event on an other object. The advantage of using this form, intead of other.on(event, callback), is that listenTo allows the object to keep track of the events, and they can be removed all at once later on. I had to read this a few times and the given example to see that the convenience comes from tracking events on the listening object side. Using "object" and "other" for the object variable names makes it a little confusing. I didn't realize the bolded "object" meant the listener object, as opposed to the object being listened to.
- illamint 14y agoI'm really excited about the Event changes. Will definitely be updating our app as soon as possible. Thanks!
- jorde 14y agoAwesome to see the support for PATCH updates, it's something I have been missing.
- playhard 14y agoSweet. I was just having problem while updating collections. collection.update(models) now merges new changes perfectly. Really useful.
- ricardobeat 14y agojsperf doesn't seem to work in IE10: 'Backbone' is undefined.
- VeejayRampay 14y agoWill Backbone still send the whole representation of the object to the server when using PATCH? It's something that's always bugged me how I end up sending way too much stuff to the server. Great release anyway the event handling is more than welcome and Backbone has been a joy to use for the past few months. Thank you for that.
- jashkenas 14y agoNope. PUT sends a full representation of the resource to the server. PATCH just sends a patch (the updated parts), naturally.
- firefoxman1 14y agoWhat's the browser support situation for PATCH? And yes please for Events.once support.
- jashkenas 14y agoBrowsers can send it over XHR. It's more of a question of whether your backend webserver can (or will) respond to it.
- rjzzleep 14y agoi stopped reading after the first line, sold right away. should fix all those ghost view events right?
- eddieplan9 14y agoIf you are disciplined to call view.remove(), then yes
- davedx 14y agoExcellent. This release is inspiring me to give backbone another try. The PATCH update is excellent too :)
- jashkenas 14y agoThis should make it easier to remove events from either end of a bound event -- either the side that emits the messages, or the side that listens to them, depending on what you need. For views (objects that tend to listen to many events from disparate sources), yes, it should make it easier. Be sure to use the `view.listenTo(model, ...)` syntax, and call `view.remove()` when you want to get rid of the view, and you should be all set.
- jakejake 14y agothis probably isn't a bug, but just curious why the 2nd xhr parameter was removed from the collection parse handler? I was using it to check the raw response and determine if the collection had actually changed & then supress unnecessary view renders. I worked around it by just stringifying the response instead, but it was a breaking change for some of my code. Otherwise I've been playing around and it looks cool so far.
- jashkenas 14y agoBecause with the change that was made to parse more consistently ... i.e. whenever a "parse" function is defined, not just at the Ajax border, so that now if you have both `collection.parse` and `model.parse` defined, you'll get both -- parsing was no longer happening when an XHR object was necessarily available. I'm also of the mind that it ought to be a function that works purely in terms of your data. For your particular use case (call collection.fetch(), and don't re-render if nothing has changed) -- give the new collection.fetch({update: true}) a try. That should give you zero events if all of the model contents are identical to what's already in the collection.
- jakejake 14y agocool thanks for the response, that makes sense. I have my code working again but I'll check out the new fetch param as well.
- deleted 14y ago[deleted]
- zachrose 14y agoHooray for the global event bus!
- epidemian 14y agoNot like it was difficult to implement one before: EventBus = _.extend({}, Backbone.Events);
- pacomerh 14y agoYeah, from the documentation exactly here: http://documentcloud.github.com/backbone/docs/backbone.html#section-18 http://documentcloud.github.com/backbone/docs/backbone.html#...
- keda 14y agoIn the doc: - intead of other.on(event, callback), is that listenTo allows the object to keep track of the events, and they can be removed all at once later on. typo "intead". ;) Thanks for this great update. I like Backbone's Minimalist approach to structured JS programming. Love CS even more.
- jashkenas 14y agoThanks for the typo. Fixed.
- lordlarm 14y ago«The Backbone object now extends Events so that you can use it as a global event bus, if you like.» This is great, up until now I've extended the app with Backbone.Event like: App = { view = {}, model = {}, collection = {}, events = {}, _.extend(App.events, Backbone.events) Congrats on the soon-to-be 1.0 release :)
- Cthulhu_ 14y agoSame, although we use it in combination with Require, so we had an 'events' module: define(["Backbone", "underscore"], function(Backbone, _) { return _.extend({}, Backbone.Events); }); and a dependency on 'events' in all our modules: define(["Backbone", "events"), function(Backbone, Events) { // stuff Events.on("event", stuff); });
- btown 14y agoDoes anyone know when/if the Parse SDK for JS plans to incorporate these features?
- frenchfries 14y agouprgaded to 0.9.9 for my app and no worries, thanks for the update and keep up the good stuff
- aashu_dwivedi 14y agosweet i just started learning backbone , guess it well be 1.0 by the time i finish :)
- Torn 14y agoHave a look at marionette: https://github.com/marionettejs/backbone.marionette https://github.com/marionettejs/backbone.marionette Although if Backbone keeps rolling in good features marionette's usefulness gets less and less ;)
- mr_christmas 14y agoI strongly recommend anyone starting SPA development to checkout AngularJS because I've found that its close to impossible to not end up with a mess when using Backbone. I for one would never again use a library/framework just because its popular. Also (at least for me):- Backbone learning curve: 1-2 months AngularJS learning curve: 3-5 days
- pedalpete 14y agoI'm going to be trying angular, but backbone is popular for a reason. My backbone code is very easy to understand, organized and not a mess at all. It doesn't need to be for everyone, but I think your recommendation may be misplaced.
- timruffles 14y agoFUD. I've had several developers over several teams pick up Backbone significantly faster than 1-2 months. I'd strongly recommend over generalising from personal experience, and perhaps considering why Backbone has so many devs using, and contributing to, it. I've been writing MVC apps in JS and ECMA script in general (eg AS 3) for a good time now, and have used other MVCish frameworks before (Dojo, Flex etc). Backbone has a solid implementation of models, views and events. If you understand the fundamentals of Javascript (knowing event listener closures are references that'll prevent GC) and write modular code you can do great things with it without any "mess".
- blablabla123 14y agoFrom reading the other comments here I get the impression it very much depends whether someone has used JS MVC frameworks before. Having not tried any JS MVC framework before, I also have the problem of thinking backbone js doesn't seem to be so good as everybody is saying. Although I have to admit that I did not spend enough time yet. But from the examples (in particular the famous Todo example), I got the impression backbone js only works fine for apps with low complexity. But who am I to judge, having it not used yet seriously...
- 14y ago
- cfontes 14y agoAn example of this "The Backbone object now extends Events so that you can use it as a global event bus, if you like." would be great.
- Cthulhu_ 14y agoFunny, I only just finished refactoring our codebase (dozens of views, models, routers) using a 'custom' implementation of the listenTo mechanic, as well as a custom 'close' method for views that would deregister the events again: this.registeredModelEvents.push({ model: model, eventName: eventName, callback: callback, context: context }); model.on(eventName, callback, context); Here's to hoping we can update to 0.9.9 soon. Shouldn't be a problem.
- cfontes 14y agoGuys thanks for this amazing work... I am using it in my site and I am absolutely in love with this frame I am also evangelizing more Brazilians to use it :D Will port my site to it right now. The "event bus" and "listenTo" are very expected modifications I also liked the "Merge and Patch", I just got confused about the get using both CID and ID but I will take a look at the code later. I can't figure why people at ThoughtWorks had put this beauty in the freezer, I would love to hear their reasons because that " abstraction pushed too far " doesn't do it for me.
- dbattaglia 14y agoI was at the Radar event in NYC this week and was thinking the same thing. If anything I always thought Backbone minimizes abstraction compared to most frameworks.