Skip to content

Commit

Permalink
deleteInWithCleanUp needs to check if there is a value in the state b…
Browse files Browse the repository at this point in the history
…efore deleting. (#2876)

* deleteInWithCleanUp needs to check if there is a value in the state before deleting, to avoid Invalid KeyPath errors

* Got rid of string compare
  • Loading branch information
dagstuan authored and erikras committed May 4, 2017
1 parent 7f9d379 commit f0daf07
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/deleteInWithCleanUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ const createDeleteInWithCleanUp = ({ deepEqual, empty, getIn, deleteIn, setIn })
const parent = getIn(state, pathTokens.join('.'))
return parent ? setIn(state, path, undefined) : state
}
const result = deleteIn(state, path)

let result = state
if (getIn(state, path) !== undefined) {
result = deleteIn(state, path)
}

const dotIndex = path.lastIndexOf('.')
if (dotIndex > 0) {
const parentPath = path.substring(0, dotIndex)
Expand Down

0 comments on commit f0daf07

Please sign in to comment.