-
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
Is it possible to opt-out of array merging? #24
Comments
This seems to be the most common request by far. Check out this comment #32 (comment) and chime in on #14. |
Uhm, why isn't this the default behaviour when we pass in |
@TehShrike Are you open to a PR that introduces |
I'd rather not change the signature to make boolean types valid for Is this so bad? const dontMerge = (destination, source) => source
const output = deepMerge(destination, source, { arrayMerge: dontMerge }) Perhaps this use case just needs to be documented in the readme? |
Prompted by @adamreisnz's request #24 (comment)
It's worse, not DRY, and needlessly verbose in my opinion, compared to const output = deepMerge(destination, source, { arrayMerge: false }) If you use deepmerge a lot all over your code base, you're going to have to create that I'm not sure where your worry for changing the signature comes from, but as javascript is not a strongly typed language why not take advantage of the fact and allows support for A simple 3 lines of code could handle it: if (options.arrayMerge === false) {
options.arrayMerge = (destination, source) => source;
} It would just convert the |
Allowing for different types of option values is certainly valid, but it increases the complexity of the API. The job of libraries like this is to expose a sensible API. There are a hundred different use cases for merging, I'm not going to add feature bloat to favor some of them, even if it's only a few lines at a time. Check out how many issues were closed by #37 - imagine what the code base would look like if each consumer's case was handled individually. DRY is still within your grasp - as you said, if you want the same set of options everywhere by default, you can create a module in your app's codebase that defaults to those options. |
Prompted by @adamreisnz's request #24 (comment)
It's a really nice feature, but sometimes it's not the right thing.
Or is there a quick fix how to prevent the merging of all array items, but rather replace the array with the one provided as the second argument?
The text was updated successfully, but these errors were encountered: