-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
customMerge at lowest level of object #216
Comments
BTW—not urgent, as I ended up using merge-lite in the end, which calls the custom merge function at every level, so I could pick out the shares key from there. |
I also think it would be a good idea to simply have |
@dsl101 If you want |
Yeah—that kind of defeats the purpose though doesn't it? I don't want to handle all cases, just one specifically named key. |
You could do this: const opts = {
isMergeableObject: () => true
customMerge: key => {
if (key === 'shares') return sumShares
return (x, y) => {
if (myIsMergeableObject(x) && myIsMergeableObject(y)) {
return merge(x, y, opts)
}
return y
}
}
}
const result = merge(thing1, thing2, opts) Where you probably want |
@dsl101 Had the same problem. Lodash mergeWith is doing exactly what we need. |
I have objects similar to this, and need, for some keys, a custom merge to sum properties:
But it seems that
customMerge()
is only called at theuserIdX
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 callcustomMerge
at every level, not just for object types?The text was updated successfully, but these errors were encountered: