mattphillips / deep-object-diff

Deep diffs two objects, including nested structures of arrays and objects, and returns the difference. ❄️

Home Page:https://www.npmjs.com/package/deep-object-diff

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Arrays are returned as Objects,

eduarto112 opened this issue · 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

commented

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.