jsondiffpatch
jsondiffpatch copied to clipboard
Request: Merging deltas
How much work would it be to add a function to merge deltas?
This will benefit all use cases where a JSON model changes more frequently than the daltas are shipped for processing, by aggregating all deltas between shipping cycles and sending only the aggregated delta.
Benefit:
- It eliminates the issue of overflowing delta queues.
- It reduces bandwidth when shipping deltas over the wire,
- It reduces processing cycles used for consuming the deltas.
Doable?
it's not trivial, but surely it's doable, this is a duplicate of #39, a PR or some reference implementation would be welcome.
What I do is run two stacks at a time, I keep the original in a "clean" state and then a live "working" model. When I "Publish" I push the Working onto the original and save the delta between them.
I have a single "Original to now" delta (Major), and a "since last change" delta array (Minor).
I generate two diff's on changes (actually I have a long debounce on the "Major") so then I have an aggregate of changes since the last "Major" and all the minors.. If that helps at all.
I started experimenting with a small library to do this: https://github.com/marcello3d/jsondiffpatch-flatten
It seems like it's possible, but I haven't covered all the edge cases to know for sure. I'm also doing a very simplistic merge for Unidiff (concatting the changes) that should be optimized.