Merge pull request #3307 from gf3/model-matches

Add `Model::matches` as special-cased proxy to `_.matches`
This commit is contained in:
Adam Krebs
2014-12-15 12:15:33 -05:00
2 changed files with 18 additions and 0 deletions

View File

@@ -328,6 +328,11 @@
return this.get(attr) != null;
},
// Special-cased proxy to underscore's `_.matches` method.
matches: function(attrs) {
return _.matches(attrs)(this.attributes);
},
// Set a hash of model attributes on the object, firing `"change"`. This is
// the core primitive operation of a model, updating the data and notifying
// anyone who needs to know about the change in state. The heart of the beast.

View File

@@ -204,6 +204,19 @@
strictEqual(model.has('undefined'), false);
});
test("matches", 4, function() {
var model = new Backbone.Model();
strictEqual(model.matches({'name': 'Jonas', 'cool': true}), false);
model.set({name: 'Jonas', 'cool': true});
strictEqual(model.matches({'name': 'Jonas'}), true);
strictEqual(model.matches({'name': 'Jonas', 'cool': true}), true);
strictEqual(model.matches({'name': 'Jonas', 'cool': false}), false);
});
test("set and unset", 8, function() {
var a = new Backbone.Model({id: 'id', foo: 1, bar: 2, baz: 3});
var changeCount = 0;