[Pkg-javascript-commits] [backbone] 05/12: Passing through the options argument to 'change' events.
Jonas Smedegaard
js at moszumanska.debian.org
Sat May 3 16:59:40 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to tag 0.3.3
in repository backbone.
commit fa9a4c879d9d43014eeb603b610c304a276fefbc
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date: Tue Nov 30 15:35:43 2010 -0500
Passing through the options argument to 'change' events.
---
backbone.js | 10 +++++-----
test/model.js | 15 ++++++++++++++-
2 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/backbone.js b/backbone.js
index 4ca830a..a77ad53 100644
--- a/backbone.js
+++ b/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;
},
diff --git a/test/model.js b/test/model.js
index b37b99a..eb3efae 100644
--- a/test/model.js
+++ b/test/model.js
@@ -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 () {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/backbone.git
More information about the Pkg-javascript-commits
mailing list