Applies a patch to the target.
The object or array you want to mutate.
The patch to be applied.
-
result
AnyThe result after appliying the patch. -
unpatch
AnyThe output to reverse the patch. -
mutations
ArrayAn array with all the mutations applied.
import { applyPatch, TYPE } from 'dop'
const target = { a: 1 }
const patch = { b: 2 }
const { result, unpatch, mutations } = applyPatch(target, patch)
result // { a: 1, b: 2 }
unpatch // { a: 1, b: TYPE.Delete }
mutations.length // 1
mutations[0] // { old_value:TYPE.Delete, target, prop:'b', path:['b'] }const target = { a: 1 }
const patch = [1, 2, 3]
const { result, unpatch, mutations } = applyPatch(target, patch)
result // [1,2,3]To understand better how patches work check out the guide.