Open thenikso opened 5 years ago
Hm, so you want some ability to configure odiff to have special behavior on pre-determined paths? What's the core reason for your use case? Is it that those objects are huge? Or do they have cycles? Something else?
I could imagine one might want to do some custom differencing in a similar way. What if we had an API like:
odiff(a,b, {customDiff: function(path, aValue, bValue) {
// Returns no differences, essentially treating aValue and bValue as the same.
return []
// "Ignores" the objects (in I think the way you were describing) by treating bValue as a new value set
// on the object.
return [{type:'set', path:path, val:bValue}]
// You could return some other array of items, potentially custom items with different structures than the
// ones created by odiff itself.
return [
...
]
}})
I'd be open to something like this. Thoughts on that?
To give some context, my use case is quite specific as I am using odiff
to send changes to the server and this particular subfield is stored in JSON but treated like an object client side.
More generally speaking what I am looking for is for odiff
to treat some values as scalars even if they are object/arrays. In fact a "workaround" that I was attempting now was to convert that path to JSON in both objects before odiff
ing.
The API you proposed should definitely do the trick. In fact being able to manually provide a diff could enable even more convoluted use cases (ie: you want to send only an ID of an object if it has changes).
That said I would suggest to allow the customDiff
function to return true
/false
to say:
true
treat aValue
and bValue
as scalars so if there are any changes, set bValue
(aka the case I need)false
proceed as normal odiff
behaviourThis would be to simplify the usage of that particular API.
UPDATE: I have currently fixed this problem with a smarter logic on my server. That is I compute the partial diff for that sub-object starting from the stored value.
I have currently fixed this problem with a smarter logic on my server.
Ah ok. Well I'm happy to accept a PR with code for your suggestion on top of my suggestion. But it sounds like maybe you don't need it now?
I came to a point in a project I am developing where I'd need
odiff
to "ignore" an object entirely. ie:The odiff of those might look like:
While I'd need to "ignore" the
ignore
path to produce something like this:I believe that
deep-diff
has aprefilter
option to do that. Is there any way to do that withodiff
as it is today? Would it make sense instead to attempt a PR to add the "prefilter" thingy?Thanks!