982 B
982 B
Home | Installation | Usage | Types | Values | Syntax | TypeRegistry | TypeCheck
Diff / Patch
Diff
Use the Diff function to generate a sequence of edits that will transform one value into another.
const E = Value.Diff(
// const E = [
{ x: 1, y: 2, z: 3 }, // { type: 'update', path: '/y', value: 4 },
{ y: 4, z: 5, w: 6 } // { type: 'update', path: '/z', value: 5 },
); // { type: 'insert', path: '/w', value: 6 },
// { type: 'delete', path: '/x' }
// ]
Patch
Use the Patch function to apply a sequence of edits.
const A = { x: 1, y: 2 };
const B = { x: 3 };
const E = Value.Diff(A, B); // const E = [
// { type: 'update', path: '/x', value: 3 },
// { type: 'delete', path: '/y' }
// ]
const C = Value.Patch<typeof B>(A, E); // const C = { x: 3 }
Back to Home