sonnyp / JSON8

JSON toolkit for JavaScript.
ISC License
105 stars 13 forks source link

Use add/remove for array diffs #137

Open yannsartori opened 3 years ago

yannsartori commented 3 years ago

This change would utilize add/remove for the patch operation rather than just a replace.

sonnyp commented 3 years ago

Please explain why you would want to do that?

yannsartori commented 3 years ago

If one would like to see a more refined diff for their list. If I have ['a', 'b', 'c'] becoming ['a', 'c', 'd'], rather than just seeing in the diff "value is now ['a', 'c', 'd']", I could see "'b' was removed and 'd' appended".

sammaphey commented 3 years ago

Also in a situation in which you have only removed one item, for example: with a list of {a: [1, 2, 3]} becoming {a: [1, 2]} It is a lot less heavy handed to say {op: remove, path: /a/2} than{op: replace, path: /a, value: [1, 2]}. I do understand that in almost every scenario it is programmatically faster to do a replace, but you are being kind of disingenuous since it's not actually one patch per change, instead you are condensing potentially many changes into 1.

yannsartori commented 2 years ago

Any updates on this?

sonnyp commented 2 years ago

It should just be a matter of adding many tests with a and b in diff.json and completing patch with what your implementation comes up with - double check it makes sense and you're good to go.