Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Please cover what's new in 0.9.9/0/9.10 #237

henrylearn2rock opened this Issue Dec 27, 2012 · 14 comments


None yet
5 participants
  • listenTo and stopListening
  • add on a collection, with {merge: true}
  • collection update: "smart" updating of sets of models
  • HTTP Patch, when and why?
  • global event bus?
  • once event?
  • When declaring a View, options, el and tagName may now be defined as functions. What are the use cases?

addyosmani commented Dec 28, 2012

Starting point:

Things I would also like us to bring in/cover related to the above:

Jeremy on listenTo/stopListening and garbage collection:

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:

# 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.

This 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.


addyosmani commented Dec 28, 2012

Regarding merge:true for collections, lots of useful info can be determined from the unit tests:

test("merge in duplicate models with {merge: true}", 3, function() {
    var col = new Backbone.Collection;
    col.add([{id: 1, name: 'Moe'}, {id: 2, name: 'Curly'}, {id: 3, name: 'Larry'}]);
    col.add({id: 1, name: 'Moses'});
    equal(col.first().get('name'), 'Moe');
    col.add({id: 1, name: 'Moses'}, {merge: true});
    equal(col.first().get('name'), 'Moses');
    col.add({id: 1, name: 'Tim'}, {merge: true, silent: true});
    equal(col.first().get('name'), 'Tim');

similar with update but we'll want to discuss where this is practically useful.

 test("update", function() {
    var m1 = new Backbone.Model();
    var m2 = new Backbone.Model({id: 2});
    var m3 = new Backbone.Model();
    var c = new Backbone.Collection([m1, m2]);

    // Test add/change/remove events
    c.on('add', function(model) {
      strictEqual(model, m3);
    c.on('change', function(model) {
      strictEqual(model, m2);
    c.on('remove', function(model) {
      strictEqual(model, m1);

    // remove: false doesn't remove any models
    c.update([], {remove: false});
    strictEqual(c.length, 2);

    // add: false doesn't add any models
    c.update([m1, m2, m3], {add: false});
    strictEqual(c.length, 2);

    // merge: false doesn't change any models
    c.update([m1, {id: 2, a: 1}], {merge: false});
    strictEqual(m2.get('a'), void 0);

    // add: false, remove: false only merges existing models
    c.update([m1, {id: 2, a: 0}, m3, {id: 4}], {add: false, remove: false});
    strictEqual(c.length, 2);
    strictEqual(m2.get('a'), 0);

addyosmani commented Dec 28, 2012

cc @wookiehangover who did some amazing work summarizing the recent changes to 0.9.9.

Sam, I haven't noticed anyone do a deep dive that goes into the Backbone 0.9.9 changes beyond the changelog since release (e.g more examples, use-cases). Have you given any consideration to doing a write-up that covers this? :)

We've love to have one in Backbone Fundamentals, but will try to get this gradually covered as time allows otherwise.

@addyosmani as a matter of fact, I have one in the works. I'll update as soon as I have it in a gist, but, yes, I'd be happy to have it posted elsewhere :)

Thanks for the ping!


addyosmani commented Dec 28, 2012

Yay! SO stoked to hear that @wookiehangover :) We're happy to give you credit for anything we're able to pull in when you have something ready to share. Cheers for working on that!


addyosmani commented Jan 15, 2013

@wookiehangover just wanted to check in to see how things are going with your post idea :)


addyosmani commented Jan 23, 2013

Looking through the list of changes in 0.9.9, I see a few key areas we need to work on upgrading:

  • Internals (high priority)
  • Tutorial 1 and 2
  • Rest of the examples

Jeremy covered the high-level points we should look at in his comment here but we should likely just work our way through the changelog for 0.9.9 and 0.9.10.

Would anyone be interested in helping us upgrade the book to the latest version of Backbone? This would mean a lot as I and other contributors are currently focused on finishing other sections of the project.


orizens commented Jan 24, 2013

Hi @addyosmani.
by Tutorial 1 and 2, you refer to one of the practicals examples https://github.com/addyosmani/backbone-fundamentals/tree/gh-pages/practicals ?


addyosmani commented Jan 24, 2013

I do indeed mean the practicals, yes. The ones you referred to are the runnable examples whilst the code in the book would equally need to be updated. Right now the book is the first pain-point we want to address.


addyosmani commented Jan 26, 2013

@henrylearn2rock I've added a brief changlog for users wanting to upgrade from 0.9.2 to 0.9.10 as a start but I'm now reviewing what should be done for the rest of the book.

As a reader, would you mind the 0.9.10/1.0 updates being in the appendix with explanations or would you expect the entire book (I guess primarily the internals chapter) to feature these changes?


sindresorhus commented Jan 26, 2013

As a reader, I would prefer everything to be as in sync with the latest Backbone version as possible.


addyosmani commented Jan 26, 2013

From Jeremy: https://twitter.com/addyosmani/status/295118883130589185

@sindresorhus I would ideally <3 to update everything to be in sync, but we don't currently have the time to :/

What I am working on is an upgrade guide for 0.9.2 -> 0.9.10/1.0 which will provide instructions and code samples in the appendix. We could bring those in as changes throughout the book when time is more available.


addyosmani commented Mar 16, 2013

I feel we have fairly good coverage of the latest version at the moment, but do still need to update the Basics chapter to have better sync with the latest Backbone docs. If anyone would like to help with this, please let me know otherwise I'll look at it once I've worked through the rest of the technical reviews.


addyosmani commented Mar 22, 2013

This will continue being addressed as a part of #378

@addyosmani addyosmani closed this Mar 22, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment