deep-object-diff icon indicating copy to clipboard operation
deep-object-diff copied to clipboard

Arrays are returned as Objects,

Open eduarto112 opened this issue 3 years ago • 3 comments

I tried this library to do some diffs between two typescript objects and the problem that I faced in was that when the difference was returned all the arrays that i had in the object were converted to objects with keys the index of the element in the array

eduarto112 avatar Mar 14 '22 11:03 eduarto112

  • https://github.com/mattphillips/deep-object-diff/issues/23
  • https://github.com/mattphillips/deep-object-diff/issues/14

morozovkirill avatar Mar 23 '22 17:03 morozovkirill

Hi, I have a solution to this problem.

Using lodash.merge to merge diff data, you can convert array-like objects to arrays.

I encountered this problem, which is to compare the old and new data of the server, return only the differences, and then merge them together on the front end.

let oldData = null

const patch = diff(oldData, data)
// Convert an array-like object to an array, then store
// The lodash.merge method is used
oldData = cloneDeep(merger({}, patch))

// Send patch data to the front end
send(path)

Hope it helps you.

yeshimei avatar Jul 02 '22 03:07 yeshimei