jsondiffpatch icon indicating copy to clipboard operation
jsondiffpatch copied to clipboard

Export DiffContext, PatchContext, ReverseContext?

Open schnerd opened this issue 4 years ago • 1 comments

I wrote a jsondiffpatch plugin arrays-by-hash a few years ago that tracks changes to items in arrays using their objectHash instead of their index. When I wrote it I was naively importing a few things from the /src directory of jsondiffpatch:

var DiffContext = require('jsondiffpatch/src/contexts/diff').DiffContext;
var PatchContext = require('jsondiffpatch/src/contexts/patch').PatchContext;
var ReverseContext = require('jsondiffpatch/src/contexts/reverse').ReverseContext;
var lcs = require('jsondiffpatch/src/filters/lcs');

When the build process changed after version v0.2.5, the src directory is no longer present – this makes sense but also means that developers cannot get access these *Context objects when writing their plugins. The default array filters use these objects, so any developer who hopes to override this behavior is out of luck – someone in #254 also ran into this issue.

Can we export some of these modules as a part of the public API? Happy to submit a PR.

Alternatively the project could add arrays-by-hash like functionality natively, I see numerous users running into this #269, #254, #154, #167, and it's pretty much essential if you want reliable merge-like functionality where you apply multiple distinct patches to an object.

schnerd avatar May 13 '20 00:05 schnerd

I opened a PR against your repo to resolve the issue: https://github.com/schnerd/jsondiffpatch-arrays-by-hash/pull/2

AesSedai avatar Jan 14 '22 04:01 AesSedai