Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arrays are returned as Objects, #79

Open
eduarto112 opened this issue Mar 14, 2022 · 2 comments
Open

Arrays are returned as Objects, #79

eduarto112 opened this issue Mar 14, 2022 · 2 comments

Comments

@eduarto112
Copy link

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

@morozovkirill
Copy link

@yeshimei
Copy link

yeshimei commented Jul 2, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants