Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

feat(angular.extend) - Simple non-breaking change to support deep extend #10507

Closed
wants to merge 4 commits into from
Closed

Conversation

prettycode
Copy link

People use angular.extend() as a utility function, whether or not it's designed for that purpose. It can easily be extended to support recursive merging with very very minor additions. Developers coming to Angular expect extend() to support this.

@googlebot
Copy link

CLAs look good, thanks!

@prettycode
Copy link
Author

Is there a way to rerun the job that failed? It's a timeout, not an explicit (test) failure.

@lgalfaso
Copy link
Contributor

git commit --amend --date "`date -R`"
git push -f

@lgalfaso
Copy link
Contributor

also, please squash all the commits into one

var h = dst.$$hashKey;
var h = dst.$$hashKey,
argsLength = arguments.length,
isDeep = (argsLength >= 3) && (arguments[argsLength - 1] === true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: each of these declarations should have its own var for clarity

@lgalfaso
Copy link
Contributor

simple question, why is it that angular.extends({}, angular.copy(foo)) not good enough? Is this just the fact that you have to also call angular.copy?

@caitp
Copy link
Contributor

caitp commented Dec 17, 2014

I think config = angular.extends({}, angular.copy(defaultConfig), angular.copy(config)); is a bit more verbose than it really needs to be.

I don't see a huge problem with adding this, not to say that there aren't things I dislike about it.

@caitp
Copy link
Contributor

caitp commented Dec 17, 2014

Oh, I should add that config = angular.extends({}, angular.copy(defaultConfig), angular.copy(config)); is semantically different from config = angular.extends({}, defaultConfig, config, true);

@caitp
Copy link
Contributor

caitp commented Dec 17, 2014

@petebacondarwin what's your opinion? Normally we just tell people to "use lodash", but it's not a very big change, I don't really see the harm in this one

dst[key] = obj[key];
var src = obj[key];

if (isDeep && Object.keys(src).length) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the value is null or undefined, Object.keys() will throw here... Don't worry about checking the type I guess, it's fine

@prettycode
Copy link
Author

I'm afraid I may be in over my head here. Tried to squash the multiple commit (sorry) into one via this, but I'm still seeing multiple commits:

git rebase -i HEAD~8
git push -f

@caitp
Copy link
Contributor

caitp commented Dec 17, 2014

@prettycode what do you see when you run git rebase -i HEAD~8? you should get an editor screen, and you'll want to replace the "pick" on the left side of the last 7 commits with "f" to squash it. Careful not to squash too many =)

delete arguments[argsLength - 1];
}

for (var i = 1; i < argsLength; i++) {
var obj = arguments[i];
if (obj) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You misunderstood me in that last commit --- I mean on line 353, the condition should not be if (obj), it should be if (isObject(obj) || isFunction(obj))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this change, please.

@prettycode
Copy link
Author

Thanks for your help, caitp! Sorry for my inexperience with git. Updating tests and the if(obj) check you referenced (the comment I misunderstood).

@petebacondarwin
Copy link
Contributor

@caitp - Oh go on then :-)


for (var i = 1, ii = arguments.length; i < ii; i++) {
if (isDeep) {
delete arguments[argsLength - 1];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (isDeep) --argsLength;

We don't need to delete anything, it's slow, and deleting the argument doesn't really do anything meaningful (it doesn't change the length value). I said this in like the first 3 comments =)

dst[key] = obj[key];
var src = obj[key];

if (isDeep && isObject(dst[key])) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If dst[key] is anything other than an object, we really need to replace it with an object --- I think copy() will use an Array if the source is an array, too.

@petebacondarwin
Copy link
Contributor

Closing in favour of #10519

caitp added a commit that referenced this pull request Mar 3, 2015
hansmaad pushed a commit to hansmaad/angular.js that referenced this pull request Mar 10, 2015
netman92 pushed a commit to netman92/angular.js that referenced this pull request Aug 8, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants