AmpersandJS / ampersand-subcollection

Filterable, sortable, proxy of a collection that behaves like a collection.
MIT License
21 stars 8 forks source link

Function comparator are not working for me #14

Closed jrmyio closed 9 years ago

jrmyio commented 10 years ago

In the docs: "If you pass a function that names two incoming arguments it will be used as a native Array.prototype.sort, where you get passed two models and return a 1, 0, -1 to specify how they compare."

However, looking at the code i only see: if (this.comparator) newModels = _.sortBy(newModels, this.comparator);

Is this functionality implemented or am i missing something?

latentflip commented 10 years ago

Yeah, this is definitely not working.

We need the code from collection (https://github.com/AmpersandJS/ampersand-collection/blob/master/ampersand-collection.js#L211-L239) that verifies comparator argument length and figures out what to do.

We should do this as part of AmpersandJS/ampersand#36 let's create a sort module which takes sort(array, comparator, options) and does the right thing: Either plucking props from the items in the array, or calling a 1 or 2 argument function and does the right thing.

bear commented 9 years ago

Closing this per the discussion in https://github.com/AmpersandJS/ampersand-state/pull/80#issuecomment-62478206