Skip to content

Commit

Permalink
fix: #791 return 'nothing' should produce undefined patch
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate committed Jun 24, 2021
1 parent 58b74a6 commit 5412c9f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 9 additions & 1 deletion __tests__/patch.js
Expand Up @@ -5,7 +5,8 @@ import produce, {
produceWithPatches,
enableAllPlugins,
isDraft,
immerable
immerable,
nothing
} from "../src/immer"

enableAllPlugins()
Expand Down Expand Up @@ -1277,3 +1278,10 @@ test("#648 assigning object to itself should not change patches", () => {
}
])
})

test("#791 patch for nothing is stored as undefined", () => {
const [newState, patches] = produceWithPatches({abc: 123}, draft => nothing)
expect(patches).toEqual([{op: "replace", path: [], value: undefined}])

expect(applyPatches({}, patches)).toEqual(undefined)
})
5 changes: 3 additions & 2 deletions src/plugins/patches.ts
Expand Up @@ -20,7 +20,8 @@ import {
Archtype,
die,
isDraft,
isDraftable
isDraftable,
NOTHING
} from "../internal"

export function enablePatches() {
Expand Down Expand Up @@ -190,7 +191,7 @@ export function enablePatches() {
patches.push({
op: REPLACE,
path: [],
value: replacement
value: replacement === NOTHING ? undefined : replacement
})
inversePatches.push({
op: REPLACE,
Expand Down

0 comments on commit 5412c9f

Please sign in to comment.