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

Array item order matters, however When object in an Array change order, no diff is generated #18

Closed
dhwang opened this issue Mar 18, 2020 · 2 comments

Comments

@dhwang
Copy link

dhwang commented Mar 18, 2020

Need to be able to show that two items in an array switched order for example

{ a : [ { id: b, value: 1}, {id: a, value: 2}] }

{ a : [ { id: a, value: 2}, {id: b, value: 1}] }

should show a difference as order matters in an array

@nahtnam
Copy link

nahtnam commented Mar 26, 2020

Looks like it works:

var changesets = require('diff-json');

console.log(changesets.diff(
  { a : [ { id: 'b', value: 1}, {id: 'a', value: 2}] },
  { a : [ { id: 'a', value: 2}, {id: 'b', value: 1}] }));

returns

[ { type: 'update',
    key: 'a',
    embededKey: '$index',
    changes: [ [Object], [Object] ] } ]

@viruschidai
Copy link
Owner

yes, it should work by default

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