Closed thesunny closed 8 years ago
Note: One way to implement this in a nice decoupled fashion is to have a build method that takes the patch and the revert and returns a revertible patch.
var revertiblePatch = ooPatch.buildRevertiblePatch(patch, revert);
assert.equal(patch, ooPatch.getPatch(revertiblePatch));
assert.equal(revert, ooPatch.getRevert(revertiblePatch));
With this mechanism in place, it's trivial to be able to build an application that stores its history in a very compact manner.
Sorry for the late reply.
The encoding could even be used with other JSON patch libraries.
Yes, maybe I should extract pack/unpack to a new module.
Other diff libraries are also having issues with revert because it goes off of the standard in some ways (e.g. a diff by itself doesn't have enough information to generate a revert) so some are contemplating going off standard or asking for the standard to be changed.
I haven't looked into this for a while but I don't think a "revert" patch cannot be a standard JSON patch. So I don't think there is need for a new format/standard.
proof: https://github.com/JSON8/patch/pull/10 this passes the entire json patch test suite with "revert" as a standard JSON patch
https://github.com/JSON8/patch/pull/15 here is a buildPatchFromRevert solution, please comment
Closing, let's move the discussion to https://github.com/JSON8/patch/pull/15
Overview
Create a Revertible Patch Format.
Create a non-standard revertible patch format that you can extract standard forward and revert patches from.
Details
One of the things I really like about JSON8 is its support for compression that expands to the standard patch format. The encoding could even be used with other JSON patch libraries.
The addition of the revert as standard diff (from sonnyp assuming its accepted) also follows the format of sticking to the standard and building on it rather than doing an augmented version of the standard.
Other diff libraries are also having issues with revert because it goes off of the standard in some ways (e.g. a diff by itself doesn't have enough information to generate a revert) so some are contemplating going off standard or asking for the standard to be changed.
My suggestion is to basically create a "JSON patch with revert format".
The alternative (which is my current plan) is that I create a PatchSet that includes both the forward diff and the revert diff in it. Of course, it is much larger than it needs to be since there is redundant information but it does solve the problem.
With the "JSON patch with revert format", a delete operation would result in a data structure that includes enough information to do the revert add operation.
We would call a method on this RevertiblePatch object to get back either a forward diff or a revert diff.
I believe this is a good format because you ultimately end up with JSON objects that comply with the standard.