aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorR. Merkert2013-04-16 20:09:43 -0400
committerPete Bacon Darwin2013-05-08 13:04:08 +0100
commit016e1e675e717ab851759eac5be640bd2f238331 (patch)
treeb3c7f753ca2fa55efecf079dab71949811c1e46a /src
parent1240641f765f7bcef8c6050fd04e9c4530b9e0c2 (diff)
downloadangular.js-016e1e675e717ab851759eac5be640bd2f238331.tar.bz2
fix(angular): do not copy $$hashKey in copy/extend functions.
Copying the $$hashKey as part of copy/extend operations makes little sense since hashkey is used primarily as an object id, especially in the context of the ngRepeat directive. This change maintains the existing $$hashKey of an object that is being copied into (likewise for extend). It is not uncommon to take an item in a collection, copy it, and then append it to the collection. By copying the $$hashKey, this leads to duplicate object errors with the current ngRepeat. Closes #1875
Diffstat (limited to 'src')
-rw-r--r--src/Angular.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/Angular.js b/src/Angular.js
index 0d8de4ae..829743a3 100644
--- a/src/Angular.js
+++ b/src/Angular.js
@@ -195,6 +195,21 @@ function nextUid() {
return uid.join('');
}
+
+/**
+ * Set or clear the hashkey for an object.
+ * @param obj object
+ * @param h the hashkey (!truthy to delete the hashkey)
+ */
+function setHashKey(obj, h) {
+ if (h) {
+ obj.$$hashKey = h;
+ }
+ else {
+ delete obj.$$hashKey;
+ }
+}
+
/**
* @ngdoc function
* @name angular.extend
@@ -208,6 +223,7 @@ function nextUid() {
* @param {...Object} src Source object(s).
*/
function extend(dst) {
+ var h = dst.$$hashKey;
forEach(arguments, function(obj){
if (obj !== dst) {
forEach(obj, function(value, key){
@@ -215,6 +231,8 @@ function extend(dst) {
});
}
});
+
+ setHashKey(dst,h);
return dst;
}
@@ -569,12 +587,14 @@ function copy(source, destination){
destination.push(copy(source[i]));
}
} else {
+ var h = destination.$$hashKey;
forEach(destination, function(value, key){
delete destination[key];
});
for ( var key in source) {
destination[key] = copy(source[key]);
}
+ setHashKey(destination,h);
}
}
return destination;