mirror of
https://github.com/jashkenas/backbone.git
synced 2026-01-22 21:38:00 -05:00
Passing through the options argument to 'change' events.
This commit is contained in:
10
backbone.js
10
backbone.js
@@ -186,7 +186,7 @@
|
||||
}
|
||||
|
||||
// Fire the `"change"` event, if the model has been changed.
|
||||
if (!options.silent && this._changed) this.change();
|
||||
if (!options.silent && this._changed) this.change(options);
|
||||
return this;
|
||||
},
|
||||
|
||||
@@ -207,7 +207,7 @@
|
||||
if (!options.silent) {
|
||||
this._changed = true;
|
||||
this.trigger('change:' + attr, this);
|
||||
this.change();
|
||||
this.change(options);
|
||||
}
|
||||
return this;
|
||||
},
|
||||
@@ -230,7 +230,7 @@
|
||||
for (attr in old) {
|
||||
this.trigger('change:' + attr, this);
|
||||
}
|
||||
this.change();
|
||||
this.change(options);
|
||||
}
|
||||
return this;
|
||||
},
|
||||
@@ -309,8 +309,8 @@
|
||||
|
||||
// Call this method to manually fire a `change` event for this model.
|
||||
// Calling this will cause all objects observing the model to update.
|
||||
change : function() {
|
||||
this.trigger('change', this);
|
||||
change : function(options) {
|
||||
this.trigger('change', this, options);
|
||||
this._previousAttributes = _.clone(this.attributes);
|
||||
this._changed = false;
|
||||
},
|
||||
|
||||
@@ -148,7 +148,7 @@ $(document).ready(function() {
|
||||
equals(model.get('two'), null);
|
||||
});
|
||||
|
||||
test("Model: changed, hasChanged, changedAttributes, previous, previousAttributes", function() {
|
||||
test("Model: change, hasChanged, changedAttributes, previous, previousAttributes", function() {
|
||||
var model = new Backbone.Model({name : "Tim", age : 10});
|
||||
model.bind('change', function() {
|
||||
ok(model.hasChanged('name'), 'name changed');
|
||||
@@ -162,6 +162,19 @@ $(document).ready(function() {
|
||||
equals(model.get('name'), 'Rob');
|
||||
});
|
||||
|
||||
test("Model: change with options", function() {
|
||||
var value;
|
||||
var model = new Backbone.Model({name: 'Rob'});
|
||||
model.bind('change', function(model, options) {
|
||||
value = options.prefix + model.get('name');
|
||||
});
|
||||
model.set({name: 'Bob'}, {silent: true});
|
||||
model.change({prefix: 'Mr. '});
|
||||
equals(value, 'Mr. Bob');
|
||||
model.set({name: 'Sue'}, {prefix: 'Ms. '});
|
||||
equals(value, 'Ms. Sue');
|
||||
});
|
||||
|
||||
test("Model: save within change event", function () {
|
||||
var model = new Backbone.Model({firstName : "Taylor", lastName: "Swift"});
|
||||
model.bind('change', function () {
|
||||
|
||||
Reference in New Issue
Block a user