Skip to content

Commit

Permalink
fix: comparison typo
Browse files Browse the repository at this point in the history
This bug prevented Immer from _not_ generating a "replace" patch when the new value is identical to the old value.
  • Loading branch information
aleclarson committed Jan 21, 2019
1 parent 551d877 commit 48b371c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
6 changes: 2 additions & 4 deletions __tests__/patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,7 @@ describe("same value replacement - 2", () => {
d.x = 4
d.x = a
},
// immer does not detect this is not an actual change
[{op: "replace", path: ["x"], value: {y: 3}}]
[]
)
})

Expand All @@ -314,8 +313,7 @@ describe("same value replacement - 4", () => {
d.x = 4
d.x = 3
},
// immer does not detect this is not an actual change
[{op: "replace", path: ["x"], value: 3}]
[]
)
})

Expand Down
2 changes: 1 addition & 1 deletion src/patches.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function generateObjectPatches(state, basePath, patches, inversePatches) {
const origValue = base[key]
const value = copy[key]
const op = !assignedValue ? "remove" : key in base ? "replace" : "add"
if (origValue === base && op === "replace") return
if (origValue === value && op === "replace") return
const path = basePath.concat(key)
patches.push(op === "remove" ? {op, path} : {op, path, value})
inversePatches.push(
Expand Down

0 comments on commit 48b371c

Please sign in to comment.