[Pkg-javascript-commits] [backbone] 36/281: Adding a _unsetAttributes property on model that stores unset attributes and appends them to the changedAttributes object.
Jonas Smedegaard
js at moszumanska.debian.org
Sat May 3 17:01:54 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 d50c5e980b4bc5e358148067587440ef933984be
Author: Irene Ros <irene at bocoup.com>
Date: Sat Oct 29 12:15:45 2011 -0400
Adding a _unsetAttributes property on model that stores unset attributes and appends them to the changedAttributes object.
---
backbone.js | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
diff --git a/backbone.js b/backbone.js
index 361080d..190cb06 100644
--- a/backbone.js
+++ b/backbone.js
@@ -153,6 +153,10 @@
// after the last `"change"` event was fired.
_previousAttributes : null,
+ // A snapshot of the model's unset attributes. Used to build a
+ // changedAttributes object
+ _unsetAttributes : null,
+
// Has the item been changed since the last `"change"` event?
_changed : false,
@@ -237,6 +241,10 @@
validObj[attr] = void 0;
if (!options.silent && this.validate && !this._performValidation(validObj, options)) return false;
+ // cache the attribute as unset for changedAttributes
+ this._unsetAttributes || (this._unsetAttributes = {});
+ this._unsetAttributes[attr] = void 0;
+
// Remove the attribute.
delete this.attributes[attr];
delete this._escapedAttributes[attr];
@@ -366,23 +374,22 @@
// the server. Unset attributes will be set to undefined.
changedAttributes : function(now) {
now || (now = this.attributes);
- var old = _.clone(this._previousAttributes);
+ var old = this._previousAttributes;
+
var changed = false;
for (var attr in now) {
if (!_.isEqual(old[attr], now[attr])) {
changed = changed || {};
changed[attr] = now[attr];
}
- delete old[attr];
- }
-
- for (var attr in old) {
- if (typeof now[attr] === 'undefined') {
- changed = changed || {};
- changed[attr] = undefined;
- }
}
+ for (attr in this._unsetAttributes) {
+ changed = changed || {};
+ changed[attr] = void 0;
+ }
+
+ this._unsetAttributes = false;
return changed;
},
--
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