aboutsummaryrefslogtreecommitdiffstats
path: root/src/ngResource/resource.js
diff options
context:
space:
mode:
authorKarl Seamon2013-12-05 18:56:52 -0500
committerIgor Minar2013-12-05 16:13:04 -0800
commita55c1e79cf8894c2d348d4cf911b28dcc8a6995e (patch)
tree6ddb88b437003e3ea3670f4d22115dbf4ce59566 /src/ngResource/resource.js
parentd070450cd2b3b3a3aa34b69d3fa1f4cc3be025dd (diff)
downloadangular.js-a55c1e79cf8894c2d348d4cf911b28dcc8a6995e.tar.bz2
chore($resource): Use shallow copy instead of angular.copy
Replace calls to angular.copy with calls to a new function, shallowClearAndCopy. Add calls to copy for cache access in $http in order to prevent modification of cached data. Results in a measurable improvement to the startup time of complex apps within Google. Closes #5300
Diffstat (limited to 'src/ngResource/resource.js')
-rw-r--r--src/ngResource/resource.js25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/ngResource/resource.js b/src/ngResource/resource.js
index e2499864..8e63c4e8 100644
--- a/src/ngResource/resource.js
+++ b/src/ngResource/resource.js
@@ -25,6 +25,25 @@ function lookupDottedPath(obj, path) {
}
/**
+ * Create a shallow copy of an object and clear other fields from the destination
+ */
+function shallowClearAndCopy(src, dst) {
+ dst = dst || {};
+
+ angular.forEach(dst, function(value, key){
+ delete dst[key];
+ });
+
+ for (var key in src) {
+ if (src.hasOwnProperty(key) && key.substr(0, 2) !== '$$') {
+ dst[key] = src[key];
+ }
+ }
+
+ return dst;
+}
+
+/**
* @ngdoc overview
* @name ngResource
* @description
@@ -393,7 +412,7 @@ angular.module('ngResource', ['ng']).
}
function Resource(value){
- copy(value || {}, this);
+ shallowClearAndCopy(value || {}, this);
}
forEach(actions, function(action, name) {
@@ -465,7 +484,7 @@ angular.module('ngResource', ['ng']).
if (data) {
// Need to convert action.isArray to boolean in case it is undefined
// jshint -W018
- if ( angular.isArray(data) !== (!!action.isArray) ) {
+ if (angular.isArray(data) !== (!!action.isArray)) {
throw $resourceMinErr('badcfg', 'Error in resource configuration. Expected ' +
'response to contain an {0} but got an {1}',
action.isArray?'array':'object', angular.isArray(data)?'array':'object');
@@ -477,7 +496,7 @@ angular.module('ngResource', ['ng']).
value.push(new Resource(item));
});
} else {
- copy(data, value);
+ shallowClearAndCopy(data, value);
value.$promise = promise;
}
}