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

feat(extend): optionally deep-extend when last parameter is true #10519

Closed
wants to merge 5 commits into from

Conversation

caitp
Copy link
Contributor

@caitp caitp commented Dec 18, 2014

Same as #10507 but with my review comments addressed and jscs fixed.

Someone quickly review this so we can land it :<

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request) and all commit authors, but as best as we can tell these commits were authored by someone else. If that's the case, please add them to this pull request and have them confirm that they're okay with these commits being contributed to Google. If we're mistaken and you did author these commits, just reply here to confirm.

@@ -333,7 +333,7 @@ function setHashKey(obj, h) {
* Extends the destination object `dst` by copying own enumerable properties from the `src` object(s)
* to `dst`. You can specify multiple `src` objects. If you want to preserve original objects, you can do so
* by passing an empty object as the target: `var object = angular.extend({}, object1, object2)`.
* Note: Keep in mind that `angular.extend` does not support recursive merge (deep copy).
* Note: Pass `true` in as the last argument to perform a recursive merge (deep copy).
Copy link
Contributor

Choose a reason for hiding this comment

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

We ought to have a @param tag for this but I am not sure how that fits with the variable argument src.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, it's not super clear how that would work... Maybe you could hack dgeni to process arguments that end with ... (or begin with ...) as a spread of parameters or something

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bloody autocorrect renames "dgeni" to "degree" -.-

@lgalfaso
Copy link
Contributor

there is something odd in having an optional parameter after a variable number of parameters... why not put this optional parameter second?

});


it('should create an empty array if destination property is a non-object and source property is an array when deep-extending', function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

'should create a new array ...'?

@petebacondarwin
Copy link
Contributor

Apart from the minor docs/comments notes I made this looks good to me.

@caitp
Copy link
Contributor Author

caitp commented Dec 18, 2014

there is something odd in having an optional parameter after a variable number of parameters... why not put this optional parameter second?

It would be lovely to do it that way, but it would be a breaking change... This is what I didn't like about the PR in the first place, but it doesn't seem "that bad" really

@lgalfaso
Copy link
Contributor

Why would it be a breaking change?

there is something odd in having an optional parameter after a variable
number of parameters... why not put this optional parameter second?

It would be lovely to do it that way, but it would be a breaking change...
This is what I didn't like about the PR in the first place, but it doesn't
seem "that bad" really


Reply to this email directly or view it on GitHub
#10519 (comment).

}
}
}

setHashKey(dst, h);
if (isDeep !== 0xFACECAFE) setHashKey(dst, h);
Copy link
Member

Choose a reason for hiding this comment

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

We should probably still attach a hashkey if h is defined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, I think that makes sense, will get rid of FACECAFE =)

Copy link

Choose a reason for hiding this comment

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

Ich bin bis 05.01.2015 abwesend.

Ich werde vertreten durch Herrn T. Landgraf und Herrn D. Neander.

Hinweis: Dies ist eine automatische Antwort auf Ihre Nachricht "Re:
[angular.js] feat(extend): optionally deep-extend when last parameter is
true (#10519)" gesendet am 20.12.2014 03:58:31.

Diese ist die einzige Benachrichtigung, die Sie empfangen werden, während
diese Person abwesend ist.=

@btford btford modified the milestones: 1.3.8, 1.3.9 Dec 19, 2014
@PatrickJS
Copy link
Member

I rather have angular.extend and angular.merge (for deep-extend)

angular.merge() is like angular.extend(), but will "deeply" copy object properties from source
objects.
@caitp
Copy link
Contributor Author

caitp commented Dec 20, 2014

@gdi2290 I've implemented your suggestion --- It's slightly more code but it doesn't really make a big difference, so I'm fine with either one or neither

Previously, hashKeys were copied from source objects and subsequently deleted or replaced with the
original. Now, there is no need to delete properties (which can be expensive), and no need to track
the initial hashKey value.
@PatrickJS
Copy link
Member

@caitp thanks, in the merge tests you should probably remove the third argument

merge(dst, src, true);

@caitp
Copy link
Contributor Author

caitp commented Dec 20, 2014

heh missed a few --- but they won't matter anyway, it's good to have them even to verify it won't throw on primitives :>

@petebacondarwin
Copy link
Contributor

I'll tweak the tests and land this today.

@petebacondarwin petebacondarwin self-assigned this Mar 3, 2015
@caitp caitp closed this in c0498d4 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.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants