Skip to content

Commit

Permalink
Dont delete initialValues structure on withCleanUp
Browse files Browse the repository at this point in the history
  • Loading branch information
ms88privat committed Nov 17, 2017
1 parent df718b8 commit e32110e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/deleteInWithCleanUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ function createDeleteInWithCleanUp<DIM, DIL>({
setIn
}: Structure<DIM, DIL>) {
const deleteInWithCleanUp = (state: DIM | DIL, path: string): DIM | DIL => {
let initialValuesPath = null

if (path.startsWith('values')) {
initialValuesPath = path.replace('values', 'initial')
}

if (path[path.length - 1] === ']') {
// array path
const pathTokens = toPath(path)
Expand All @@ -19,7 +25,10 @@ function createDeleteInWithCleanUp<DIM, DIL>({
}

let result: DIM | DIL = state
if (getIn(state, path) !== undefined) {

const initialValueComparison = initialValuesPath ? (getIn(state, initialValuesPath) === undefined) : true

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

Expand All @@ -29,6 +38,9 @@ function createDeleteInWithCleanUp<DIM, DIL>({
if (parentPath[parentPath.length - 1] !== ']') {
const parent = getIn(result, parentPath)
if (deepEqual(parent, empty)) {
if (initialValuesPath) {
return deleteInWithCleanUp(result, parentPath)
}
return deleteInWithCleanUp(result, parentPath)
}
}
Expand Down

0 comments on commit e32110e

Please sign in to comment.