flitbit / diff

Javascript utility for calculating deep difference, capturing changes, and applying changes across objects; for nodejs and the browser.
MIT License
2.99k stars 213 forks source link

Incorrectly formed deleted array element #168

Open gluhovalexey opened 4 years ago

gluhovalexey commented 4 years ago

These are two arrays, they differ in the middle element var o1 = {files: [{pages: [{id: 1, name: 'abc'},{id: 2, name: 'def'},{id: 3, name: 'jhk'}]} ]} var o2 = {files: [{pages: [{id: 1, name: 'abc'},{id: 3, name: 'jhk'}]} ]}

diff Shows the following result:

DiffArray index: 2 item: DiffDeleted {kind: "D", lhs: Object {id: 3, name: "jhk"}} kind: "A" path: ["files", 0, "pages"]"

That is, always the last element

ndraiman commented 4 years ago

I have encountered the same issue, any changes in array returns the last element as changed.

As a workaround, if the diff array is larger than 1, I'm concatenating the index of the last "edited" element.

Created a stackblitz as example

Miller547719886 commented 2 years ago

any progress?

serdarsrts commented 1 year ago

any progress?