Merge pull request #3507 from akre54/matches-with-callback

Matches with predicate
This commit is contained in:
Adam Krebs
2015-03-20 11:33:01 -04:00
5 changed files with 512 additions and 427 deletions

View File

@@ -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

View File

@@ -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"]
}

View File

@@ -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",

View File

@@ -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});

File diff suppressed because it is too large Load Diff