Giter VIP home page Giter VIP logo

filtered-collection's Issues

#setFilter is a terrible API. Change it.

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.

Better support for sort

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);

Adding version number

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.

Possible issue with inherited _onModelEvent

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 be efficient with add and remove events

Filtering should pay attention to add/remove events closely.

  • Apply filtering to just the new element (on add) and insert it propperly.
  • A removed element should just be removed without any new filtering going on (if it is already filtered out).
  • A single Add/Remove should not reset the entire collection.

Need an event which signifies that filtering is complete

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.

Convert to Gem

Converted into a gem, in addition to having a bit more structure, this would be easily importable into a rails app.

Render my view collection before filter.

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.

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.