JSON8 / patch

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

buildPatchFromRevert #15

Closed sonnyp closed 8 years ago

sonnyp commented 8 years ago

Better alternative to https://github.com/JSON8/patch/pull/10

In #10 the revert property would be a valid JSON patch but it comes with a cost. With this, we don't break the API, the revert property is still not a valid JSON patch but can be transformed to it easily using buildPatchFromRevert

var doc = {foo: 'bar'}
var patch = [...]
var patching = ooPatch.apply(doc, patch, {reversible: true})
doc = patching.doc

//
// know you can revert 2 different ways 
//

// the old way
doc = ooPatch.revert(doc, patching.revert)

// OR

// the new way - ideal for packing/unpacking, saving, ...
var revertPatch = ooPatch.buildPatchFromRevert(patching.revert) // valid JSON Patch
doc = ooPatch.apply(doc, revertPatch)

This looks like a big patch it can be resumed to rename foo method to 'buildPatchFromRevert` and export it. The rest is documentation and moving code around for better clarity and smaller builds.

sonnyp commented 8 years ago

this is not a breaking change so merging into develop, please feel free to comment and I may address in an other PR