Skip to content

Commit

Permalink
Merge pull request jashkenas#3507 from akre54/matches-with-callback
Browse files Browse the repository at this point in the history
Matches with predicate
  • Loading branch information
akre54 committed Mar 20, 2015
2 parents 1262263 + 499f6af commit bf73153
Show file tree
Hide file tree
Showing 5 changed files with 512 additions and 427 deletions.
2 changes: 1 addition & 1 deletion backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@

// Special-cased proxy to underscore's `_.matches` method.
matches: function(attrs) {
return _.matches(attrs)(this.attributes);
return !!_.iteratee(attrs, this)(this.attributes);
},

// Set a hash of model attributes on the object, firing `"change"`. This is
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version" : "1.1.2",
"main" : "backbone.js",
"dependencies" : {
"underscore" : ">=1.6.0"
"underscore" : ">=1.7.0"
},
"ignore" : ["docs", "examples", "test", "*.yml", "*.html", "*.ico", "*.md", "CNAME"]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"keywords" : ["model", "view", "controller", "router", "server", "client", "browser"],
"author" : "Jeremy Ashkenas <jeremy@documentcloud.org>",
"dependencies" : {
"underscore" : ">=1.6.0"
"underscore" : ">=1.7.0"
},
"devDependencies": {
"coffee-script": "1.7.1",
Expand Down
13 changes: 13 additions & 0 deletions test/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,19 @@
strictEqual(model.matches({'name': 'Jonas', 'cool': false}), false);
});

test("matches with predicate", function() {
var model = new Backbone.Model({a: 0});

strictEqual(model.matches(function(attr) {
return attr.a > 1 && attr.b != null;
}), false);

model.set({a: 3, b: true});

strictEqual(model.matches(function(attr) {
return attr.a > 1 && attr.b != null;
}), true);
})

test("set and unset", 8, function() {
var a = new Backbone.Model({id: 'id', foo: 1, bar: 2, baz: 3});
Expand Down
Loading

0 comments on commit bf73153

Please sign in to comment.