From 1a84d4da7ce350fb75fa55970d2d998960a8ac85 Mon Sep 17 00:00:00 2001 From: Josh Duff Date: Thu, 17 Aug 2017 10:18:58 -0500 Subject: [PATCH 1/3] Adding a note about how to avoid merging arrays Prompted by @adamreisnz's request https://github.com/KyleAMathews/deepmerge/issues/24#issuecomment-322996001 --- README.markdown | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.markdown b/README.markdown index 27ca536..8affefa 100644 --- a/README.markdown +++ b/README.markdown @@ -98,6 +98,13 @@ function concatMerge(destinationArray, sourceArray, options) { merge([1, 2, 3], [3, 2, 1], { arrayMerge: concatMerge }) // => [1, 2, 3, 3, 2, 1] ``` +To prevent arrays from being merged: + +```js +const dontMerge = (destination, source) => source +const output = deepMerge(destination, source, { arrayMerge: dontMerge }) +``` + #### clone Defaults to `false`. If `clone` is `true` then both `x` and `y` are recursively cloned as part of the merge. From 51d9158fbbe58eae26bc3a43e7a125042b1fa881 Mon Sep 17 00:00:00 2001 From: Josh Duff Date: Thu, 17 Aug 2017 10:22:09 -0500 Subject: [PATCH 2/3] Whoops, renaming It's `merge` everywhere else in the file... --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 8affefa..485da58 100644 --- a/README.markdown +++ b/README.markdown @@ -102,7 +102,7 @@ To prevent arrays from being merged: ```js const dontMerge = (destination, source) => source -const output = deepMerge(destination, source, { arrayMerge: dontMerge }) +const output = merge(destination, source, { arrayMerge: dontMerge }) ``` #### clone From 22762f63a0ff8b735db02341f3609e835a6ae88d Mon Sep 17 00:00:00 2001 From: Josh Duff Date: Thu, 17 Aug 2017 10:26:12 -0500 Subject: [PATCH 3/3] Fixing more wrongness Why did I think I could copy/paste without thinking --- README.markdown | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 485da58..ff81e3b 100644 --- a/README.markdown +++ b/README.markdown @@ -102,7 +102,8 @@ To prevent arrays from being merged: ```js const dontMerge = (destination, source) => source -const output = merge(destination, source, { arrayMerge: dontMerge }) +const output = merge({ coolThing: [1,2,3] }, { coolThing: ['a', 'b', 'c'] }, { arrayMerge: dontMerge }) +output // => { coolThing: ['a', 'b', 'c'] } ``` #### clone