TehShrike / deepmerge

A library for deep (recursive) merging of Javascript objects
MIT License
2.75k stars 216 forks source link

customMerge on constructor #197

Open xenoterracide opened 4 years ago

xenoterracide commented 4 years ago

I want to merge a @js-joda/core type, these apparently can't be cloned simply by value... so I'm looking at customMerge, but I realize I'll more or less have to write it for every key... I mean, I can do some functional magic... What I'd really like to do, is have some kind of a check function that could work on the constructor, and then run the custom merge.

maybe something like

mergers:[ {
    should( key, x, y ): boolean,
    merge( x, y ): unknown
}]

this way the algorithm will just continue if should returns false

in this case all I really want is to return right if defined, and left if not, since these are immutable value objects no need to try to do a special copy.

TehShrike commented 4 years ago

This sounds like it overlaps with https://github.com/TehShrike/deepmerge/issues/184 and https://github.com/TehShrike/deepmerge/issues/176 – how do the solutions proposed in those threads sound to you?