-
Notifications
You must be signed in to change notification settings - Fork 20
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
Fix #12 by adding a _.mergeWith customizer function #13
Conversation
|
Thanks for the PR! I think you're right in the fact that it makes more sense that arrays are fully merged, rather than some items being replaced the way they are right now. This would constitute a breaking change in the library, but I am personally OK with that. |
const outputJSON = _.merge({}, ...files); | ||
const outputJSON = _.mergeWith({}, ...files, (objValue, srcValue, key, object, source, stack) => { | ||
if (Array.isArray(objValue) && Array.isArray(srcValue)) return [...objValue, ...srcValue]; | ||
return undefined; // handle it just like with _.merge |
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.
Just to make sure I understand, returning undefined
means "do whatever lodash
would normally do by default" and not "replace with undefined
", right?
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.
Yes, exactly, that's according to their specification.
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.
This now breaks my use cases so I am sticking to 2.0. Would it have been better to provide a customizer fn as a prop for the node package for custom use cases such as these.
Since we're changing some behavior here, I would really appreciate it if you could add a test case! That would help make sure that it's really clear how this library merges arrays. |
Sure, I'll try to do this in the next couple of days. |
Hey @alexlafroscia @moqmar any updates on this? We would really love to see thing merged as we are blocked by currenty behaviour |
Not from me -- still waiting for some tests! |
Whoops, totally forgot about this - I've added a test case for this now. 🙃 |
Thanks @moqmar ! |
|
See #12 for details