Giter Site home page Giter Site logo

backbone-filtered-collection's People

Contributors

jmorrell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

backbone-filtered-collection's Issues

removeFilter doesn't seem to work

In my view I do this:

this.filteredCollection.filterBy({ "LastModified": statusFilter });

The problem I have is that removeFilter doesn't work, even if I call it immediately after the previous line:

this.filteredCollection.removeFilter("LastModified");

this._filters[filterName] is undefined in the removeFilter function.

As a side note I would to also support something like this for removing a filter:

this.filteredCollection.filterBy({ "LastModified": null });

This would make for better logics in many cases (if you already decided to remove a filter on another level in your code).

Keep up the good work!

Advice on de-duplicating collection methods?

I have logic that applies to the collection in aggregate โ€” for example, getting min/max extents for various properties, or calculating durations.

Sometimes I need to run it on the full collection, but often I need the exact same logic for the filtered collection. Right now, I'm finding myself writing two copies of the same method, one for the collection, and one for the filtered collection.

Any suggestion on how to do that in a cleaner fashion?

Suggestion: For key:value filters run models change event refiltering only if filtered key changed

If I have big collection and filtered collection with some specific key filtered by. Like "project_id" for example. Now I change "visibility" to all models in original collection. Result: I have 500ms lug because each model triggers "change:visibility" and filtered collection recheck each model. But there is enough meta information at that moment not to do this. In this case models should be rechecked only if project_id property changes.

_collection.set instead of _collection.reset on execFilter ?

I'm using backbone-filtered-collection in combination with Marionette's CollectionView.
Originally, CollectionView renders one child view for every item in the collection. The views in my app are quite complex and some pages contain a few hundred of these in one CollectionView. Because Marionette does that synchronously, that blocks the browser for a few seconds (and that results in a bad user experience).

To fix that I came up with the following plan:

Instead of giving the original Backbone.Collection to the CollectionView I would give it a FilteredCollection to render, that has a filter including only the first 20 items (enough to fill the screen "above the fold"). Then, a few milliseconds after page load, add a filter that includes only the first 30 items, remove the first filter, so CollectionView would render additional 10 child views, and so on, somewhat like this:

var show_first = 20;
var increase_collection = function() {
  if (show_first > original_collection.length) {
    return;
  }
  show_first += 10;
  filtered_collection.filterBy("first_" + show_first, function(item) {
    return (item.collection.indexOf(item)) < show_first;
  });
  filtered_collection.removeFilter("first_" + (show_first - 10));
  setTimeout(increase_collection, 50);
};

increase_collection();

However ... in execFilter the underlying _collection is resetted every time a filter is applied:

this._collection.reset(filtered);

[https://github.com/jmorrell/backbone-filtered-collection/blob/880672e7edbc3eb2151f569fe009d62d03d989c4/backbone-filtered-collection.js#L87]

This causes the CollectionView to (following the example given above) remove 20 child views, then add 30 new childviews. Quite the opposite to what I want to achieve.

If I change my local copy so that the line reads

this._collection.set(filtered);

instead, everything is smooth, the proper 'add' events are fired and only additional child views are rendered.

Is there a particular reason to use reset here instead of set ?

Filtered collections trigger "reset" when underlying collection sorts

This started in 3dc90ef. In my app, I pass a filtered collection into a marionette collection view, which rerenders its children when the collection resets. This reset happens too often for me, because if the collection has a sort key, just adding a record will trigger sort on the underlying collection, and hence a reset on the filtered one.

I'm also confused, why would we need to run the filters after a sort? Presumably a sort shouldn't change the membership, just the order. Would it be possible to define a handler other than execFilter for sort, which does not trigger reset?

Edit: I should have put this first. Thanks for open sourcing and maintaining this library. It really makes my backbone code a lot nicer!

Not instanceof Backbone.Collection

This module is incompatible with code that checks for obj instanceof Backbone.Collection. Is there a reason why these collections aren't simply extended from Backbone.Collection?

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.