deepmerge
deepmerge copied to clipboard
customMerge at lowest level of object
I have objects similar to this, and need, for some keys, a custom merge to sum properties:
const thing1 = {
userId1: {
shares: 3
}
}
const thing2 = {
userId1: {
shares: 2
}
}
const sumShares = (s1, s2) => s1 + s2
const opts = {
customMerge: key => {
if (key === 'shares') return sumShares
}
}
const result = merge(thing1, thing2, opts)
But it seems that customMerge()
is only called at the userIdX
level, not at the lowest level. In reality, the objects are big and complex, but certain keys like this need special handling. Is there a way to call customMerge
at every level, not just for object types?