-
Notifications
You must be signed in to change notification settings - Fork 216
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
Allow the source object to be null or undefined #54
Comments
It's important to realize that You may want to look into deep-assign. That said, I would be open to returning a clone of the first argument when the second argument is null or undefined. I think it would just take wrapping this block with an Unless anyone else has any thoughts, I'll say a pull request with tests would be welcome. |
Nope, they are so different:
|
It's true - deep-assign has optimal compatibility with |
If nobody is motivated to open pull requests with tests or implementation, I'll close this eventually. |
Should If so, should that be the case when it's passed in to the target, or just the source? See #80 |
typeof null is an object... so it would probably make sense to treat it like {}. Not sure if we should do the same with undefined though. |
If this library mutates objects by changing its properties (which is what it has done), then I don't like the idea of treating null or undefined as special "empty object" values. But if this library is moving to an "always clone onto a new object no matter what" paradigm (like I'm pushing it to), it's more understandable. |
I still feel really nervous about adding magical defaults :-x Cloning is a non-trivial thing to have a mental model for (as you can see by looking back over all the issues and pull requests on this repository), I don't want to try to guess at what people will expect here. |
My workaround for this is to use the .all method which takes an array, then use
|
This path has too many scary implications for me. I'm going to close this. |
For those really needing this I use this as a work around. const deepmerge = require('deepmerge');
const merge = (first, second) => deepmerge({ object: first }, { object: second }).object;
merge({ }, undefined); // undefined |
Could you provide the same behaviour like
Object.assign
?The text was updated successfully, but these errors were encountered: