Skip to content
Myr

fix: #791 return 'nothing' should produce undefined patch

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

authored by Michel Weststrate · committed by Michel Weststrate · parent 58b74a6 · Browse files · 2 files+12 added−3 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+12 added−3 removed

  • tests:+9 added−1 removed
  • other:+3 added−2 removed

2 files+12 added−3 removed

modified:__tests__/patch.js+9 added-1 removed
3 unmodified lines
4 applyPatches,5 produceWithPatches,6 enableAllPlugins,7 isDraft,8 immerable8 immerable,9 nothing10} from "../src/immer"1112enableAllPlugins()13
1263 unmodified lines
1277 value: 11278 }1279 ])1280})12811282test("#791 patch for nothing is stored as undefined", () => {1283 const [newState, patches] = produceWithPatches({abc: 123}, draft => nothing)1284 expect(patches).toEqual([{op: "replace", path: [], value: undefined}])12851286 expect(applyPatches({}, patches)).toEqual(undefined)1287})
modified:src/plugins/patches.ts+3 added-2 removed
18 unmodified lines
19 ProxyType,20 Archtype,21 die,22 isDraft,23 isDraftable23 isDraftable,24 NOTHING25} from "../internal"2627export function enablePatches() {28 const REPLACE = "replace"
161 unmodified lines
190 ): void {191 patches.push({192 op: REPLACE,193 path: [],193 value: replacement194 value: replacement === NOTHING ? undefined : replacement195 })196 inversePatches.push({197 op: REPLACE,198 path: [],
101 unmodified lines