-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Apply clone option to target object #209
Open
creativeux
wants to merge
10
commits into
TehShrike:master
Choose a base branch
from
creativeux:clone-target-false
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
97833ed
Apply clone option to target object
b9020e0
Apply target mutation to merge.all first array entry
10deb35
Missing index on return
38d54b2
Index madness. Oops.
cf8ef25
Add cloneWithTarget flag
971f5e6
merge with target, not clone with target...
c5688b7
Remove unnecessary boolean cast
3b66e4c
Handle undefined target
dadd37e
Improve undefined source / target testing
4c0d549
Incomplete assertion definitions
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 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 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
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.
@RebeccaStevens does this need to account for
options.clone
scenarios for objects that are not the root target? I've read through it a few times and withdeepmerge
being self-referenced, I wonder if there's a case where this function would be called in reference to an object nested deeper than the entrypoint where we might want to return the target here in the case whereoptions.clone
isfalse
?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.
No I don't think so. This function is only called at most once per call of the main deepmerge function.
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.
Per my last commit, this is called repeatedly during recursion down an object tree. Not sure if this changes your thought on the topic.
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.
Specifically,
deepmerge
is returned fromcloneUnlessOtherwiseSpecified
which can callmergeObject
which callsgetDestinationObject
.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.
I think I'm seeing the issue you are talking about here.
I think withoptions.mergeWithTarget: true
&options.clone: false
, merging with each target going down should happen.I think withoptions.mergeWithTarget: true
&options.clone: true
, merging should only happen with the top most target.Actually no, scrap that. Merging should only ever happen with the top most target.
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.
Looking at the codebase, it doesn't really look set up to be able to add this functionality easily in a non-hacky way.
A bunch of refactoring may be needed (which I'm in the process of doing in #215).
If you want to just do it in a hacky way, you could just remove
mergeWithTarget
from the options object before it is passed to the recursive call.