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

Js Array diff problem #290

Open
pcelica88 opened this issue Jun 3, 2020 · 1 comment
Open

Js Array diff problem #290

pcelica88 opened this issue Jun 3, 2020 · 1 comment

Comments

@pcelica88
Copy link

I noticed that there is a problem with comparing arrays.
The problem only occurs:

  • when we add a new element to the beginning of the array

  • and when we are showing unchanged values

Example

var left = {"ids": [1, 2, 3]};
var right = {"ids": [4, 1, 2, 3]};
var delta = jsondiffpatch.diff(left, right);
Results
In this case only the replacement of the first element will be detected, and what I need is completely added new element without replacing first one.

Can you please check if this is a bug or this should work like this.
Thanks

@fw623
Copy link

fw623 commented Jul 24, 2020

It anyone is wondering, this is just a bug/misleading on the demo page.

It correctly patches it:

const left = { "ids": [1, 2, 3] }
const right = { "ids": [4, 1, 2, 3] }

const delta = jsondiffpatch.diff(left, right) // { ids: { '0': [ 4 ], _t: 'a' } }
const reconstructedRight = jsondiffpatch.patch(left, delta) // { ids: [ 4, 1, 2, 3 ] }

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

2 participants