Skip to content
Myr

fix: ensure that patches are reusable. Fixes #411

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Michel Weststrate · committed by GitHub · parents a16deda, 49b2e7b · Browse files · 2 files+56 added−12 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+56 added−12 removed

  • tests:+27 added−1 removed
  • other:+29 added−11 removed

2 files+56 added−12 removed

modified:__tests__/patch.js+27 added-1 removed
1"use strict"2import produce, {setUseProxies, applyPatches} from "../src/index"2import produce, {3 setUseProxies,4 applyPatches,5 produceWithPatches6} from "../src/index"78jest.setTimeout(1000)910function runPatchTest(base, producer, patches, inversePathes) {
74 unmodified lines
85 const patch = {op: "add", path: ["a", "b", "c"], value: 1}86 applyPatches({}, [patch])87 }).toThrowErrorMatchingSnapshot()88 })89 it("applied patches cannot be modified", () => {90 // see also: https://github.com/immerjs/immer/issues/41191 const s0 = {92 items: [1]93 }9495 const [s1, p1] = produceWithPatches(s0, draft => {96 draft.items = []97 })9899 const replaceValueBefore = p1[0].value.slice()100101 const [s2, p2] = produceWithPatches(s1, draft => {102 draft.items.push(2)103 })104105 applyPatches(s0, [...p1, ...p2])106107 const replaceValueAfter = p1[0].value.slice()108109 expect(replaceValueAfter).toStrictEqual(replaceValueBefore)110 })111})112113describe("simple assignment - 1", () => {114 runPatchTest(
443 unmodified lines
modified:src/patches.js+29 added-11 removed