-
Notifications
You must be signed in to change notification settings - Fork 634
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
feat(collections): add deepMerge
#1075
Conversation
Tried on my end. Even typing seems working recursively with many cases. Great work! But I found some cases where the typing doesn't match to the result, for example:
here c.a is "a", but it has |
Thanks for implementing this! I am really excited about a standardized Some notes:
|
I'll try to investigate to solve these typing issues if possible 👍 It's possible that it comes from But if you have any leads on how to fix this, I'll take them 🙂 Thanks for taking time to review and advise on this feature |
(see comment below) |
There are almost more typing logic than the actual algorithm but result seems worth it 🙂 I think this is ready for review, I don't have anything to add and this seems goods to me for a first iteration |
Awesome! I will take a look tonight. Looking forward to it :-) |
}; | ||
|
||
/** | ||
* How does recursive typing works ? |
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.
Great explanation! 👏
Me and @lowlighter are in contact on Discord to finish this @kt3k , this will likely be ready for final review tomorrow. |
Remove cloning and non enumerable properties
@kt3k we have decided to remove TL;DR: This is ready to be merged^^ |
Instead of naming it |
It doesn't mutate the left operand like assign though. A new object is created instead |
@lowlighter I think it would be a good idea to have it function more like the native shallow version aka assign, in a sense that it should mutate a target object and merge n objects instead of just two. That makes the function more flexible. const mutatedA = deepAssign(a, b, c) To create a new object const d = deepAssign({}, a, b, c) |
Merging inplace was the original the design, but I've been told that std/collections' philosophy is to never mutate inplace and instead return a new object instead. As for variable arguments I'm not against but it would make it awkward to pass options I think |
@timreichen I think |
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.
LGTM. Awesome work! @lowlighter @LionC
All functions in |
I am sorry to write this after it has already been merged. But I think |
Because |
Yes, but even there the function name of the API is |
This implements
deepMerge
, which merges deeply two records together into the first one.For convenience, a few options are proposed to handle edge cases:
arrays
,sets
andmaps
can change their merging strategy from"replace"
to"concat"
. In the latter mode, values from both records will be keptincludeNonEnumerable
can be used to include properties and symbols which have an hidden visibilityAdditional implementation notes:
PropertyKey
types are supported (includingsymbol
)RegExp
,Date
, ...) and user classes won't be treated as objects, so the recursive merging won't apply on them (instead their reference is just replaced in target record)Ref: #1065
Partial<T> : T
merge
insteadREADME.md