Permalink
Browse files

filter complete events respect silent

  • Loading branch information...
1 parent 3a0bd4b commit 6f041375df080c75f14649e20d6e722310f00138 @dlikhten committed Jan 13, 2013
Showing with 21 additions and 4 deletions.
  1. +9 −3 backbone-filtered-collection.js
  2. +12 −1 spec/javascripts/backbone-filtered-collection-spec.js
@@ -74,6 +74,8 @@ SOFTWARE.
}
,_modelChanged: function(model, collection, options){
+ options || (options = {});
+
var ownIndexOfModel = this.indexOf(model);
if (this.collectionFilter(model)){
// Model passed filter
@@ -88,7 +90,9 @@ SOFTWARE.
this._forceRemoveModel(model, {index: ownIndexOfModel});
}
}
- this._filterComplete();
+ if (! options.silent) {
+ this._filterComplete();
+ }
}
,resortCollection: function() {
@@ -156,9 +160,9 @@ SOFTWARE.
}
,setFilter: function(newFilter, options) {
+ options || (options = {});
if (newFilter === false) { newFilter = this.defaultFilter } // false = clear out filter
this.collectionFilter = newFilter || this.collectionFilter || this.defaultFilter;
- options || (options = {});
// this assumes that the original collection was unmodified
// without the use of add/remove/reset events. If it was, a
@@ -189,7 +193,9 @@ SOFTWARE.
}
}
}, this);
- this._filterComplete();
+ if (! options.silent) {
+ this._filterComplete();
+ }
}
,_onModelEvent: function(event, model, collection, options) {
@@ -84,6 +84,17 @@ describe("Backbone.FilteredCollection", function() {
expect(collection.models[3].get("value")).toEqual(6)
expect(collection.models[4].get("value")).toEqual(8)
});
+
+ it("should not trigger a filter-complete event if options.silent is true", function() {
+ count = 0;
+ collection.on("filter-complete", function() {
+ count += 1;
+ });
+
+ collection.setFilter(createLessthanFilter(0), {silent: true});
+
+ expect(count).toEqual(0);
+ });
});
describe("event:add", function() {
@@ -224,7 +235,7 @@ describe("Backbone.FilteredCollection", function() {
});
});
- describe("model - event:delete", function() {
+ describe("model - event:destroy", function() {
it("should just remove the model from the base collection like normal, and raise no problems with the filter", function() {
collection.setFilter(createLessthanFilter(5));
origModelZero = collection.models[0];

0 comments on commit 6f04137

Please sign in to comment.