ampersand-subcollection
Advanced tools
Comparing version 1.4.4 to 1.4.5
@@ -49,3 +49,3 @@ var _ = require('underscore'); | ||
configure: function (opts, clear) { | ||
if (clear) this._reset(); | ||
if (clear) this._resetFilters(); | ||
this._parseFilters(opts); | ||
@@ -76,5 +76,10 @@ this._runFilters(); | ||
_reset: function () { | ||
this.models = []; | ||
this._resetFilters(); | ||
}, | ||
// just reset filters, no model changes | ||
_resetFilters: function () { | ||
this._filters = []; | ||
this._watched = []; | ||
this.models = []; | ||
this.limit = undefined; | ||
@@ -81,0 +86,0 @@ this.offset = undefined; |
{ | ||
"name": "ampersand-subcollection", | ||
"description": "Filterable, sortable, proxy of a collection that behaves like a collection.", | ||
"version": "1.4.4", | ||
"version": "1.4.5", | ||
"author": "Henrik Joreteg <henrik@andyet.yet>", | ||
@@ -6,0 +6,0 @@ "bugs": { |
@@ -117,2 +117,6 @@ # ampersand-subcollection | ||
## changelog | ||
- 1.4.5 fixed bug where passing the `reset` option to `configure()` wasn't working. | ||
## credits | ||
@@ -119,0 +123,0 @@ |
@@ -334,1 +334,39 @@ var test = require('tape'); | ||
}); | ||
test('reset works correctly/efficiently when passed to configure', function (t) { | ||
var base = getBaseCollection(); | ||
var sub = new SubCollection(base, { | ||
where: { | ||
sweet: true | ||
} | ||
}); | ||
var itemsRemoved = []; | ||
var itemsAdded = []; | ||
var awesomeIds = sub.pluck('id'); | ||
t.equal(sub.length, 50, 'should be 50 that match initial filter'); | ||
sub.on('remove', function (model) { | ||
itemsRemoved.push(model); | ||
}); | ||
sub.on('add', function (model) { | ||
itemsAdded.push(model); | ||
}); | ||
sub.configure({ | ||
where: { | ||
sweet: true, | ||
awesomeness: 6 | ||
} | ||
}, true); | ||
t.equal(sub.length, 10, 'should be 10 that match second filter'); | ||
t.equal(itemsRemoved.length, 40, 'five of the items should have been removed'); | ||
t.equal(itemsAdded.length, 0, 'nothing should have been added'); | ||
t.ok(_.every(itemsRemoved, function (item) { | ||
return item.sweet === true && item.awesomeness !== 6; | ||
}), 'every item removed should have awesomeness not 6 and be sweet: true'); | ||
t.end(); | ||
}); |
24433
495
129