-
Notifications
You must be signed in to change notification settings - Fork 27
Open
Description
var Model = require('ampersand-model');
var Collection = require('ampersand-collection').extend({model: Model, comparator: 'attribute'});
var models = [new Model, new Model, new Model];
var collection = new Collection();
collection.reset(models);
console.log(models.map(function(m){return m.cid}));
console.log(collection.models.map(function(m){return m.cid}));
results:
['state1','state2','state3']
['state3', 'state2', 'state1']
Models will get sorted in reverse order when the comparator attribute is undefined on a model.
This result can be replicated in chrome and firefox but not phantom js.
This works correctly in Backbone.Collection
as it uses the underscore sortBy
method and not Array.prototype.sort
.
Swapping these two lines https://github.com/AmpersandJS/ampersand-collection/blob/v1.3.17/ampersand-collection.js#L227-228 (and https://github.com/AmpersandJS/ampersand-collection/blob/v1.3.17/ampersand-collection.js#L235-236) seems to do the trick for chrome and firefox but breaks phantom js.