Comments (5)
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.
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.
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.
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.
from backbone.virtualcollection.
Related Issues (20)
- Adding items to a sorted virtual collection does not trigger sort event HOT 5
- Not compatible with 0.9.2 HOT 1
- NPM is not up to date HOT 2
- Change event triggered without options.index causes error HOT 1
- Source Missing License Header HOT 2
- Listen to a specific attribute changes in a model in a virtual collection
- Publish 0.5.2 to NPM HOT 2
- Create a virtual collection from multiple collections HOT 3
- Support Backbone.PageableCollection HOT 4
- IE8 fix HOT 6
- Caching, disabling and re-enabling subsets HOT 2
- Models added twice to a virtual collection HOT 7
- Problem with Sort when not overridden HOT 7
- Backbone update event not being handled HOT 5
- Add a License and Re-Publish to NPM HOT 1
- Garbage Collection HOT 5
- Option for creating deaf collections HOT 2
- Event "change:attr" is not handled in some cases HOT 6
- make backbone a peer dependency HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from backbone.virtualcollection.