Giter VIP home page Giter VIP logo

Comments (5)

hashchange avatar hashchange commented on August 23, 2024

Interesting catch ... and thank you for your helpful description! I'll deal with the issue further down the road. I can't say for sure that I'll actually fix it - after all, the issue relates to undocumented Backbone behaviour. On the other hand, Backbone is meant to be hacked, so it would make sense to make it work. I'll have a look.

from backbone.select.

hashchange avatar hashchange commented on August 23, 2024

Sorry for the delay ... I've had a closer look now. As far as I can see, a fix would have to replace Backbone.Collection with a modified implementation.

The issue is that Backbone parses the models and creates the models property after initialize() is called. That order would have to be reversed. The fix I have in mind would look something like this:

var originalConstructor = Backbone.Collection;

Backbone.Collection = Backbone.Collection.extend( {

    constructor: function ( models, options ) {

        if ( options && options.parse ) ) { 
            models = this.parse( models, options ) || [];
            options = _.extend( {}, options, { parse: false } );
        }

        originalConstructor.call( this, models, options );

    }

} );

That would do the trick (presumably), but I don't like it for two reasons.

First, the options object handed to initialize() is no longer the one which was passed in. initialize() receives a clone, and the parse option has changed to false, in order to prevent a second parse call. That alone might be enough to break stuff for some people.

Second, it's a heavy-handed approach. It would place otherwise unneccessary constraints on the load order of components: Backbone.Select would have to be loaded after Backbone, but before anything else.

Imagine the fallout e.g. in an AMD setup. Every component which depends on Backbone would have to list Backbone.Select as a dependency, too. A shim would be required for pretty much every Backbone-related third-party module. I don't think that's worth it, given that we are dealing with an undocumented feature.

So I'll leave things as they are. However, if you disagree or have a different idea for a fix, just let me know. And thanks for the report!

from backbone.select.

hashchange avatar hashchange commented on August 23, 2024

I retract everything I've said ;) Seems like I'll be able to fix it cleanly in the upcoming version 2.

from backbone.select.

nmackey avatar nmackey commented on August 23, 2024

Sounds great, thanks.

from backbone.select.

hashchange avatar hashchange commented on August 23, 2024

Has landed in 2.0.0.

from backbone.select.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.