benjamine / jsondiffpatch

Diff & patch JavaScript objects
MIT License
4.83k stars 472 forks source link

Export DiffContext, PatchContext, ReverseContext? #285

Open schnerd opened 4 years ago

schnerd commented 4 years ago

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.

AesSedai commented 2 years ago

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