JSON8 / patch

Moved to https://github.com/sonnyp/JSON8/tree/master/packages/patch
ISC License
20 stars 2 forks source link

Support packing/unpacking during diff/apply #3

Open Akkuma opened 8 years ago

Akkuma commented 8 years ago

This library is probably one of the only json patch implementations that has a serializer that can pack/unpack operations to reduce the size/verbosity of the implementation. My recommendation is to allow a user to do that at the same time, so there is no performance penalty during the initial diff or apply.

patch.diff(obj1, obj2, true) for packing while diffing.

sonnyp commented 8 years ago

I don't think the performance penalty is worth the effort as it is probably very minimal. If you can provide a use case where it makes sense I'll consider it. (PR would be accepted)

Akkuma commented 8 years ago

I'm suggesting that you replace the patches created through diff to use your serialized format if pack: true is passed to diff.

I'm not asking for what amounts to pack(diff()). I'm asking for https://github.com/JSON8/patch/blob/master/lib/diff.js#L18 to use [0, "/a/b/c", ["foo", "bar"]] when pack: true. There should not be any overhead in this and would remove overhead a separate pack function is creating.

The use case is fairly simple. JSON Patch is fairly verbose compared to the packed format and certainly is more verbose, although arguably more flexible, than JSON Merge Patch. By baking in the packing all at once, you get something that is better than standard JSON Patch and closer to size of JSON Merge.