

Backbone.js 0.9.9 Released - jashkenas
http://backbonejs.org/?0-9-9#changelog

======
jashkenas
This 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

~~~
drewda
Is 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?

~~~
jashkenas
Somewhat. 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.

~~~
eric-hu
A 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.

~~~
jashkenas
Yes -- I struggled for a while with the wording of that. I've you've got a re-
phrasing that would make it clearer, I'm all ears.

~~~
eric-hu
This explanation actually provides 2 examples, one before the description text
and one after. The description refers to the example before:

> listenTo object.listenTo(other, event, callback)

I think changing the naming to be more specific and updating the description
names could help out.

    
    
       listenTo  observingObject.listenTo(actingObject, event, callback)
    

One caveat is that this breaks consistency with the other examples in this
section (i.e. object.once(...) object.trigger(...)).

------
lordlarm
«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_
Same, 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);
        });

------
keda
In 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
Thanks for the typo. Fixed.

------
cfontes
Guys 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
I 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.

------
Cthulhu_
Funny, 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
An 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.

------
zachrose
Hooray for the global event bus!

~~~
epidemian
Not like it was difficult to implement one before:

    
    
        EventBus = _.extend({}, Backbone.Events);

~~~
pacomerh
Yeah, from the documentation exactly here:
[http://documentcloud.github.com/backbone/docs/backbone.html#...](http://documentcloud.github.com/backbone/docs/backbone.html#section-18)

------
btown
Does anyone know when/if the Parse SDK for JS plans to incorporate these
features?

------
frenchfries
uprgaded to 0.9.9 for my app and no worries, thanks for the update and keep up
the good stuff

~~~
aashu_dwivedi
sweet i just started learning backbone , guess it well be 1.0 by the time i
finish :)

~~~
Torn
Have a look at marionette:
<https://github.com/marionettejs/backbone.marionette>

Although if Backbone keeps rolling in good features marionette's usefulness
gets less and less ;)

------
mr_christmas
I 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

~~~
timruffles
FUD. 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
From 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...

~~~
krebby
In response to your last point: take a look at some of the real world examples
that use Backbone (<http://backbonejs.org/#examples>) as compared to
builtwith.angularjs.org. Real, huge projects like Hulu, Soundcloud,
Moviepilot, and USA Today are all using Backbone incredibly successfully.
Backbone doesn't provide a lot of the "plumbing" that other frameworks like
Angular, Knockout, Batman, Spine, et al have built-in, but it's got a lot more
resources and community that work much better for doing only what you actually
need.

