Skip to content
This repository has been archived by the owner on Jul 12, 2020. It is now read-only.

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

Closed
henrylearn2rock opened this issue Dec 27, 2012 · 14 comments
Closed

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

henrylearn2rock opened this issue Dec 27, 2012 · 14 comments

Comments

@henrylearn2rock
Copy link

  • 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
Copy link
Owner

Starting point:
http://backbonejs.org/#changelog

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:

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.

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
Copy link
Owner

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
Copy link
Owner

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.

@wookiehangover
Copy link

@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
Copy link
Owner

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
Copy link
Owner

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

@addyosmani
Copy link
Owner

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
Copy link
Contributor

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
Copy link
Owner

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
Copy link
Owner

@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
Copy link
Contributor

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

@addyosmani
Copy link
Owner

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
Copy link
Owner

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
Copy link
Owner

This will continue being addressed as a part of #378

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants