jmorrell / backbone-filtered-collection

Create a filtered version of a backbone collection that stays in sync.
MIT License
63 stars 9 forks source link

Filtered collections trigger "reset" when underlying collection sorts #5

Open samwgoldman opened 10 years ago

samwgoldman commented 10 years ago

This started in 3dc90ef3085bc0b42aa9201e4c6f090fc3168ce7. 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!

jmorrell commented 10 years ago

I'm away from a computer for the rest of the night, but I'll take a look tomorrow :+1:

jmorrell commented 10 years ago

I'm also confused, why would we need to run the filters after a sort?

I didn't realize that adding a sort key would trigger the sort event on add. I originally assumed that it only fired on Collection#sort which does a full reset anyway. I'll add this use case to the unit tests and then see about fixing the performance issues you're seeing. Thanks for the heads up :)

amakhrov commented 9 years ago

@jmorrell any chance to get this fixed? PR from @samwgoldman seems to be a good solution.