-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Collection does not sort itself when elements change #76
Comments
No that is not intended, could you give an example of this? |
If I'm reading this right, I think what you want is https://github.com/AmpersandJS/ampersand-filtered-subcollection With var Collection = require('ampersand-collection');
var C = Collection.extend({comparator: 'name'});
var c = new C([{name: 'z'}, {name: 'c'}, {name: 'b'}])
console.log(c.at(0).name, c.at(1).name, c.at(2).name);
// b c z
c.at(2).name = 'a';
console.log(c.at(0).name, c.at(1).name, c.at(2).name);
// b c a
// im assuming you want it to be `a b c` |
Oh right, the collection has no way to know if attributes in an object change. So you either set the object wholly, or call sort, I think. |
What if we listened to the change:comparator event when the comparator is a string. I think it would make sense for a collection with a comparator to keep itself sorted. If you'd like I can make a pull request. Ampersand-filtered-subcollection is nice and I use it but I don't want to make a subcollection out of the entire collection for the sake of sorting. Right now I added a change listener to the collection and it works. |
When I change a property defined by the comparator the collection does not sort itself. Is this intended?
The text was updated successfully, but these errors were encountered: