Skip to content
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

Open
herkyl opened this issue Feb 5, 2016 · 4 comments
Open

Collection does not sort itself when elements change #76

herkyl opened this issue Feb 5, 2016 · 4 comments

Comments

@herkyl
Copy link

herkyl commented Feb 5, 2016

When I change a property defined by the comparator the collection does not sort itself. Is this intended?

@wraithgar
Copy link
Contributor

No that is not intended, could you give an example of this?

@lukekarrys
Copy link
Contributor

If I'm reading this right, I think what you want is https://github.com/AmpersandJS/ampersand-filtered-subcollection

With ampersand-collection the behavior is this:

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`

@wraithgar
Copy link
Contributor

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.

@herkyl
Copy link
Author

herkyl commented Feb 6, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants