jsondiffpatch icon indicating copy to clipboard operation
jsondiffpatch copied to clipboard

[question] is it possible to omit certain fields from the diff?

Open vlamic opened this issue 5 years ago • 7 comments

First of all - thanks for your library - it rocks! ❤️

I have a question. I know it's possible to use propertyFilter to exclude certain fields from participating in diff. However, these fields are still present in the resulting diff (applies for added elements). Is there an option to also exclude these field for these added elements?

Thanks!

vlamic avatar Nov 28 '18 13:11 vlamic

+1 for this feature, it is nice to be able to ignore properties but since they are still displayed it seems as if both left and right objects have the same value which is incorrect. Having a displayFilter would be nice?

Note: right now I am using lodash omit to exclude those properties but this works out of the box only on top properties so not ideal

mebibou avatar Jun 15 '21 07:06 mebibou

Hi @vlamic,

Could you please explain how you have implemented the propertyFilter to exclude certain fields? your help much appreciated?

Thanks

prasanmgc avatar Feb 18 '22 12:02 prasanmgc

@prasanmgc you just need to do propertyFilter: name => !['field1', 'field2'].includes(name) and field1/field2 won't be compared

mebibou avatar Feb 18 '22 12:02 mebibou

Thanks a lot @mebibou. It worked. you saved my time.

prasanmgc avatar Feb 18 '22 12:02 prasanmgc

@mebibou Just a quick question. Is it possible to reference the ignored fields from a class variable? I am getting an error when i use the below. propertyFilter: function (name: string) { !this.ignoredFields.includes(name); }

TypeError: Cannot read property 'ignoredFields' of undefined

prasanmgc avatar Feb 19 '22 09:02 prasanmgc

@prasanmgc I suggest you read first what this refers to in JavaScript to understand the error. But you should do this instead

var ignoredFields = [];
create({
  propertyFilter(name: string) { return !ignoredFields.includes(name); }
});

mebibou avatar Feb 19 '22 09:02 mebibou

@mebibou @prasanmgc property filter doesn't remove the fields from the nested objects, did it work for you for nested objects too?

gnyani avatar Jan 20 '23 16:01 gnyani