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

Use "add" and "remove" in preference to "replace"? #5

Open
kcarnold opened this issue Mar 6, 2015 · 1 comment
Open

Use "add" and "remove" in preference to "replace"? #5

kcarnold opened this issue Mar 6, 2015 · 1 comment

Comments

@kcarnold
Copy link

kcarnold commented Mar 6, 2015

I don't think that https://github.com/intelie/immutable-js-diff/blob/master/tests/sequenceDiff.test.js#L71 is the desired behavior; rather, it should be:

[{op: 'remove', path: '/2'},
 {op: 'add': path: '/3', value: 5}]

Note that this diff does not include 4, which did not change. Why this matters:

  1. If 4 was instead some large data structure, the patch would be unnecessarily large
  2. If we were using the patches to track the history of a single item, this patch would introduce a discontinuity in the history of 4.
@smmoosavi
Copy link

+1

Can we see move some times?
for example:

var list1 = Immutable.fromJS([1,2,3,4]);
var list2 = Immutable.fromJS([1,2,4,3]);
var result = diff(list1, list2);
// now: List [ Map { "op": "replace", "path": "/2", "value": 4 }, Map { "op": "replace", "path": "/3", "value": 3 } ]
// better: List [ Map { "op": "move", "from": "/2", "path": "/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