This repository was archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.4k
chore($resource): Use shallow copy instead of angular.copy #5252
Closed
Closed
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
677f10b
chore($resource): Use shallow copy instead of angular.copy
kseamon 4797ba7
Reverts http.js
kseamon e210f91
Removes a white space, per review.
kseamon fbc5cf5
docs(tutorial/step-12): fix refernce to incorrect jquery version
elwinarens 280b5ce
chore(closure): add `$routeProvider#redirectTo` function parameters
1e7675a
docs(input): remove deprecated isolated scope pitfall
revolunet b38a228
docs(tutorial/step-3): add module to `ng-app` directive in code sample
programistka e8f4305
docs($interpolate): demonstrate a filter in the interpolated expression
esgy d802ed1
fix($rootScope): broadcast $destroy event on $rootScope
jeffbcross 93901bd
fix($animate): ensure ms durations are properly rounded
matsko b6d5439
fix(input): ensure ngModelWatch() triggers second digest pass when ap…
21e48ab
chore(travis): move checks from before_scripts to scripts
vojtajina 0e50810
fix(ngInit): evaluate ngInit before ngInclude
958d3d5
fix($animate): ensure animations work with directives that share a tr…
matsko 04a570d
docs(TRIAGING): Initial doc about triaging issues in Angular
tbosch 39c5ffb
docs(tutorial/step-2): remember to install karma plugins
petebacondarwin 2adbcf1
docs(tutorial/step-3): remember to install karma plugins
petebacondarwin 09648e4
docs(tutorial/step-6): remove unused `class="diagram"`
mjomble 1722574
chore($resource): Use shallow copy instead of angular.copy
kseamon 89c146d
Merge branch 'shallow-copy' of https://github.com/kseamon/angular.js …
kseamon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,25 @@ function lookupDottedPath(obj, path) { | |
return obj; | ||
} | ||
|
||
/** | ||
* 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 | ||
|
@@ -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) ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also remove the trailing space while you are at it :) |
||
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; | ||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all the changes in this file should be a separate commit. I like this change but it is not related to the changes to in $resource