dlikhten / filtered-collection Goto Github PK
View Code? Open in Web Editor NEWA simple backbone.js filtered collection.
License: MIT License
A simple backbone.js filtered collection.
License: MIT License
I was reading the readme, and realized how shitty of an API setFilter is.
Desired behavior:
#setFilter(filter)
-- set the filter to the given function. Cannot be falsy.
#clearFilter()
-- clear the filter
#refilter()
-- execute the filter. Do not change the filter function
Since people are using this tool, please weigh in. I'd like to improve the API if possible.
A backbone sort event indicates no model changes occurred. This code could be more efficient at handling such an event without actually re-filtering, thus making overall app performance better (in theory)
newModels = [];
newMapping = [];
_.each(this.originalCollection.models, function(model, index) {
if (this.models.indexOf(model) >= 0) { // did you pass the filter?
newModels.push(model); // add the model in the exact order it is in the original model
newMapping.push(index);
}
});
this.models = newModels;
this.newMapping = newMappings;
this.trigger("sort", this);
Is it possible that you could include a version number on your next update. I ran into some problems with the older version of the plugin and didn't realize that I wasn't working on the most current version until reading through the code to see the differences.
Hey!
In order to be able to maintain the library and use it across projects you need to create the first tag. After tag the code I can help solving the issue #13.
Thanks
PD: We need to use http://semver.org/ to play with bower.
Just started using this, and I've been seeing an exception thrown where if model.destroy()
is called, the "destroy" event triggers _onModelEvent
on both the original Collection and on the FilteredCollection. When it's called on the FilteredCollection, it attempts to call this.remove(...)
, which is made to throw "Do not invoke directly." By copying in the functionality of _onModelEvent
, without the clause that calls this.remove(...)
, everything seems to work fine.
In essence, the FilteredCollection is getting told to remove each model twice: from the model itself via a "destroy" event, and from the original collection's "remove" event.
I'll need to isolate a test case first (I'm using the Parse.com version of Backbone, so I'm not 100% sure that this is a bug in FilteredCollection), but thought I'd submit the issue to track it.
Filtering should pay attention to add/remove events closely.
This is really useful if there does not exist an ability to individually add or remove elements to/from the rendered view. Instead if the rendered view must re-render everything, it is a bad idea to bind to add/remove events. Instead we should have a single event indicating that all filtering is done (that we know of).
Note: add/remove events should not trigger this, they indicate an element was added/removed. However if the underlying collection is a filtered collection, it should propagate the event. This way even though many individual elements may be added/removed, a single filter-complete event can occur.
Looks like there is a bug when elements are added to the filtered selection, removed, and added again. The _mappings array is not keeping track of original indices properly.
It would be great if I could use bower to install this.
Converted into a gem, in addition to having a bit more structure, this would be easily importable into a rails app.
Propagate all events from the original collection.
Hi, i have a problem with this great code, excuse me my ignorance, but when override setFilter with this
filteredItems.setFilter(function(item){
return item.get('nt') == 'Travesía' ? true : false;
});
and then call the filter and render
filteredItems.setFilter();
$("#content").html(new EventListView({model: filteredItems, page: 1}).el);
The execution flow is:
first render and then execute return item.get('nt') == 'Travesía' ? true : false;
I dont underenstand because happen this.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.