Fixed the need for try/catch around oldValue

This commit is contained in:
jos 2016-09-23 11:17:53 +02:00
parent 291cfbfa22
commit 2a1fabc6ac
1 changed files with 3 additions and 8 deletions

View File

@ -334,13 +334,6 @@ export function add (data, path, value, options) {
const resolvedPath = resolvePathIndex(data, pathArray)
const prop = resolvedPath[resolvedPath.length - 1]
// FIXME: should not be needed to do try/catch. Create a function exists(data, path), or rewrite toDataPath such that you don't need to pass data
let oldValue = undefined
try {
oldValue = getIn(data, toDataPath(data, resolvedPath))
}
catch (err) {}
let updatedData
if (parent.type === 'Array') {
// TODO: create an immutable helper function to insert an item in an Array
@ -372,7 +365,9 @@ export function add (data, path, value, options) {
})
}
if (parent.type === 'Object' && oldValue !== undefined) {
if (parent.type === 'Object' && pathExists(data, resolvedPath)) {
const oldValue = getIn(data, toDataPath(data, resolvedPath))
return {
data: updatedData,
revert: [{