mattphillips / deep-object-diff

Deep diffs two objects, including nested structures of arrays and objects, and returns the difference. ❄️
https://www.npmjs.com/package/deep-object-diff
MIT License
1.05k stars 89 forks source link

detailedDiff doesn't return deleted elements #76

Closed joniba closed 2 years ago

joniba commented 2 years ago

Deleted doesn't seem to work in the detailedDiff method. Examples:

let b1 = { a: 1 }
let b2 = {  }
console.log(JSON.stringify(differ.detailedDiff(b1, b2))); //output: {"added":{},"deleted":{},"updated":{}}
let b1 = { a: 1 }
let b2 = { b: 3 }
console.log(JSON.stringify(differ.detailedDiff(b1, b2))); //output: {"added":{"b":3},"deleted":{},"updated":{}}
mattphillips commented 2 years ago

Hey @joniba looks like this is happening because you are using JSON.stringify which doesn't support undefined which is used by this library to represent deleted values.

I think this is a duplicate of #10. This comment shows how you can use JSON.stringify with the deleted elements of a diff: https://github.com/mattphillips/deep-object-diff/issues/10#issuecomment-308224665

Going to close this but feel free to re-open / comment should I have misunderstood anything 😃