ampersand-collection
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -71,4 +71,10 @@ var BackboneEvents = require('backbone-events-standalone'); | ||
if (options.parse) attrs = existing.parse(attrs, options); | ||
existing.set(attrs, options); | ||
if (sortable && !sort && existing.hasChanged(sortAttr)) sort = true; | ||
// if this is model | ||
if (existing.set) { | ||
existing.set(attrs, options); | ||
if (sortable && !sort && existing.hasChanged(sortAttr)) sort = true; | ||
} else { | ||
// if not just update the properties | ||
extend(existing, attrs); | ||
} | ||
} | ||
@@ -88,3 +94,3 @@ models[i] = existing; | ||
if (!model) continue; | ||
if (order && (model.isNew() || !modelMap[model.id])) order.push(model); | ||
if (order && ((model.isNew && model.isNew()) || !modelMap[model.id])) order.push(model); | ||
modelMap[model.id] = true; | ||
@@ -91,0 +97,0 @@ } |
{ | ||
"name": "ampersand-collection", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"author": "Henrik Joreteg <henrik@andyet.net>", | ||
@@ -5,0 +5,0 @@ "bugs": { |
@@ -174,1 +174,13 @@ var test = require('tape'); | ||
}); | ||
test('`set` method should work for simple objects too', function (t) { | ||
var c = new Collection(); | ||
c.set([{id: 'thing'}, {id: 'other'}]); | ||
t.equal(c.length, 2, 'should have two items'); | ||
c.set([{id: 'thing', other: 'property'}], {remove: true}); | ||
t.equal(c.length, 1, 'should have one item'); | ||
var first = c.at(0); | ||
t.equal(first.id, 'thing'); | ||
t.equal(first.other, 'property'); | ||
t.end(); | ||
}); |
20125
428