[Pkg-javascript-commits] [backbone] 262/281: use `_.has` for Object proto props
Jonas Smedegaard
js at moszumanska.debian.org
Sat May 3 17:02:20 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to tag 0.9.0
in repository backbone.
commit 2a6624cb240e462486171681f175c578435857e1
Author: Brad Dunbar <dunbarb2 at gmail.com>
Date: Mon Jan 30 05:52:47 2012 -0500
use `_.has` for Object proto props
---
backbone.js | 10 ++++------
test/model.js | 10 +++++++++-
2 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/backbone.js b/backbone.js
index ee6ef0c..0991871 100644
--- a/backbone.js
+++ b/backbone.js
@@ -240,14 +240,12 @@
// Update attributes.
for (attr in attrs) {
val = attrs[attr];
- if (!_.isEqual(now[attr], val) || (options.unset && (attr in now))) {
- delete escaped[attr];
- }
+ if (!_.isEqual(now[attr], val)) delete escaped[attr];
+ options.unset ? delete now[attr] : now[attr] = val;
delete this._changed[attr];
- if (!_.isEqual(prev[attr], val) || (options.unset && (attr in prev))) {
+ if (!_.isEqual(prev[attr], val) || (_.has(now, attr) != _.has(prev, attr))) {
this._changed[attr] = val;
}
- options.unset ? delete now[attr] : now[attr] = val;
}
// Fire the `"change"` events, if the model has been changed.
@@ -386,7 +384,7 @@
// Determine if the model has changed since the last `"change"` event.
// If you specify an attribute name, determine if that attribute has changed.
hasChanged: function(attr) {
- if (attr) return attr in this._changed;
+ if (attr) return _.has(this._changed, attr);
return !_.isEmpty(this._changed);
},
diff --git a/test/model.js b/test/model.js
index 225b21e..9224a33 100644
--- a/test/model.js
+++ b/test/model.js
@@ -543,7 +543,7 @@ $(document).ready(function() {
test("unset fires change for undefined attributes", 1, function() {
var model = new Backbone.Model({x: undefined});
- model.bind('change:x', function(){ ok(true); });
+ model.on('change:x', function(){ ok(true); });
model.unset('x');
});
@@ -568,4 +568,12 @@ $(document).ready(function() {
ok(!model.hasChanged());
});
+ test("set/hasChanged object prototype props", function() {
+ var model = new Backbone.Model();
+ ok(!model.hasChanged('toString'));
+ model.set({toString: undefined});
+ model.unset('toString', {silent: true});
+ ok(model.hasChanged());
+ });
+
});
--
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