Closed tlouisse closed 3 years ago
This should hopefully do what you want (completely untested):
const result = deepmerge(targetObj, sourceObj, {
customMerge: (key) => (targetCurrLvl, sourceCurrLvl, options) => {
if ('objNeedingCustomMerge' in targetCurrLvl[key]) {
return sourceCurrLvl[key];
}
return deepmerge(targetCurrLvl, sourceCurrLvl, options);
},
});
Ah, I see, since the fallback function is deepmerge again (https://github.com/TehShrike/deepmerge/blob/master/index.js#L24) Thanks! 👍
I also noticed this merge request implements the exact thing requested above, so will wait for that as well: https://github.com/TehShrike/deepmerge/pull/228/files#diff-e727e4bdf3657fd1d798edcd6b099d6e092f8573cba266154583a746bba0f346R64
Hi,
Would it be possible to supply the target and source object to
options.customMerge
?In the situation below, I want to check for the existence of
source.objNeedingCustomMerge
. So I want to check on a child key name instead of the default key (in the below case I would getb
andc
as the 'key' parameter, but I would like to know ifsource[key].objNeedingCustomMerge
exists).Expected result:
Would it be possible to allow for this?