funcollate
v0.1.0
Published
A diff & patch tool for immutable state tree
Downloads
3
Maintainers
Readme
Funcollate
A diff & patch tool for immutable state tree.
// local.js
import { diff } from "funcollate";
const prev = {
name: "counter",
count: 0
};
const next = {
name: "counter",
count: 1
};
const d = diff(prev, next);
send(JSON.stringify(d));
// remote.js
import { patch } from "funcollate";
const prev = {
name: "counter",
count: 0
};
const d = JSON.parse(receive());
const next = patch(prev, d);
assert(next.name === "counter");
assert(next.count === 1);
assert(prev.count === 0);
API
diff(prev: T, next: T): Difference
- @param
prev
: previous state tree - @param
next
: next state tree - @return: an opaque value that represents difference and can be json serialized
Returns difference between prev
and next
.
patch(prev: T, diff: Difference): T
- @param
prev
: previous state tree - @param
diff
: difference generated bydiff
- @return: next state tree
Generates next state tree from prev
and diff
.
Mutates nothing of prev
.
Similar
- json-touch-patch - Immutable JSON Patch implementation based on RFC 6902
- redux-in-worker - Entire Redux in Web Worker