You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Then I realized that the implementation uses Arrays.prototype.concat() just like the default strategy by npm:deepmerge.
Describe the solution you'd like
Adding a "union"MergingStrategy for arrays only, preferably through a new exported type ArraysMergingStrategy.
Implementation can use the unionfunction imported from "./union.ts".
Describe alternatives you've considered
Warning
The following solution would be a BREAKING CHANGE
Splitting the MergingStrategy type into 3 separate types:
This way, it is clear what to expect from the strategy. Implementations of maps and sets do not need to change, just the name of the strategy (from "merge" to "union").
The default strategy should be "replace" for all, since the current fallback if the user entered an unmapped strategy, is to return right. Example below:
import{deepMerge}from"@std/collections/deep-merge";import{assertEquals}from"@std/assert";consta={foo: newSet(["foo"])};constb={foo: newSet(["bar"])};// @ts-expect-error: user passes unmapped strategyconstresult=deepMerge(a,b,{sets: "unmapped-strategy"});constexpected={foo: newSet(["bar"])};assertEquals(result,expected);
Is your feature request related to a problem? Please describe.
When I first tried the
deepMergefunction, I expected the default behavior to be as follows:Then I realized that the implementation uses
Arrays.prototype.concat()just like the default strategy by npm:deepmerge.Describe the solution you'd like
Adding a
"union"MergingStrategyforarraysonly, preferably through a new exported typeArraysMergingStrategy.Implementation can use the
unionfunctionimported from"./union.ts".Describe alternatives you've considered
Warning
The following solution would be a BREAKING CHANGE
Splitting the
MergingStrategytype into 3 separate types:This way, it is clear what to expect from the strategy. Implementations of maps and sets do not need to change, just the name of the strategy (from
"merge"to"union").The default strategy should be
"replace"for all, since the current fallback if the user entered an unmapped strategy, is toreturn right. Example below: