-
Notifications
You must be signed in to change notification settings - Fork 494
Open
Description
Hi all,
I want to achieve the following:
If I compare two objects with "id" property, and they have differences, in addition of the field differences to add a magic __id property to the diff.
Example:
left:
{
id: 1,
name: 'Philip'
}
right:
{
id: 1,
name: 'Peter'
}
The diff that I would get is:
{
name: ['Philip', 'Peter']
}
I want to get:
{
__id: 1,
name: ['Philip', 'Peter']
}
Now, the part that I struggle with:
I want to have __id as part of the diff only if there is a difference between the two objects
I tried with the following plugin:
const diffPluginSaveId = <any> function(context) {
// I want to add __id and __model
if (context.leftType === 'object' &&
typeof context.left.id !== 'undefined'
// ... ????
) {
console.log(context)
context.setResult({
__id: context.right.id,
__model: context.left.constructor.name
})
}
}
diffPluginSaveId.filterName = 'saveId'
const differ = jdp.create(diffConfig)
differ.processor.pipes.diff.before('collectChildren', diffPluginSaveId)
Please give me a hand :)
Thank you :)
Metadata
Metadata
Assignees
Labels
No labels