Giter Club home page Giter Club logo

Comments (5)

p3drosola avatar p3drosola commented on September 26, 2024

That's a good question @wilfriedvanasten. It brings to light the fact that I didn't really design this with inheritance in mind. Like you mentioned, cloning with all the options can have unintended side effects (in particular you lose control over the close_with option).

Can you tell me a little more about your usecase? What are you trying to achieve?

from backbone.virtualcollection.

wilfriedvanasten avatar wilfriedvanasten commented on September 26, 2024

Well the mentioned issue actually arose from using a BackGrid Extension for filtering that relied on clone to provide a cloned collection to do the filtering on. I now realize that my proposed implementation would actually result in disaster since the extension would likely use the clone to either 1) maintain the original collection or 2) to represent the filtered contents. Since it would be modifying the collection using virtual collection in either case would result in modification to the underlying collection which is totally wrong. So I will not use that extension and instead write something that works with virtual collection's filtering capabilities instead.

It does however show an interesting apparently expected behaviour of clone: That the resulting collection be completely independent of the original collection. By being bound to the underlying collection this would be hard for a "natural clone" of a virtual collection to provide. So in that sense the best approximation would actually be for clone to return a new Backbone.Collection based on the virtual collections models instead. However than the filtering behaviour would not be maintained which someone who calls VirtualCollection.clone might expect. This issue is more hairy then I initially thought.

from backbone.virtualcollection.

p3drosola avatar p3drosola commented on September 26, 2024

Yep, I get your point.

I think what would make most sense is to return a Backbone.Collection and be done with it. If what you want is a dynamic virtual collection with the same filter, we'll leave it up to the user. Because you'll need to manage the listener lifespan as well, etc. It's really not complicated, but it varies depending on your implementation.

I think it's just a matter of changing return new this.constructor for return new this.collection.constructor. But if you make a PR with tests I'll be happy to merge it.

from backbone.virtualcollection.

p3drosola avatar p3drosola commented on September 26, 2024

Ok, I'm not sure this is terribly useful, but I added support for clone. At least it doesn't throw an error.

from backbone.virtualcollection.

p3drosola avatar p3drosola commented on September 26, 2024

2e5e2fd

from backbone.virtualcollection.

Related Issues (20)

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.