Skip to content

Commit

Permalink
fix: ensure patches are reusable
Browse files Browse the repository at this point in the history
  • Loading branch information
Shuumatsu committed Aug 31, 2019
1 parent c2e69d9 commit 49b2e7b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/patches.js
Expand Up @@ -97,7 +97,7 @@ function generateObjectPatches(state, basePath, patches, inversePatches) {

// used to clone patch to ensure original patch is not modified
const clone = obj => {
if (typeof obj !== "object") return obj
if (obj === null || typeof obj !== "object") return obj

if (Array.isArray(obj)) return obj.map(clone)

Expand All @@ -109,7 +109,8 @@ const clone = obj => {

export const applyPatches = (draft, patches) => {
for (const patch of patches) {
const {path, op, value} = clone(patch)
const {path, op} = patch
const value = clone(patch.value)

if (!path.length) throw new Error("Illegal state")

Expand Down

0 comments on commit 49b2e7b

Please sign in to comment.