mirror of
https://github.com/jashkenas/backbone.git
synced 2026-04-30 03:00:06 -04:00
Merge pull request #3307 from gf3/model-matches
Add `Model::matches` as special-cased proxy to `_.matches`
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user