Skip to content

Commit

Permalink
feat: remove state slice when set as undefined
Browse files Browse the repository at this point in the history
Related to #1790
  • Loading branch information
JBBianchi committed Jul 12, 2023
1 parent 9acbbab commit 07ec766
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions packages/core/src/reducers/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import cloneDeep from 'lodash/cloneDeep';
import setFp from 'lodash/fp/set';
import unsetFp from 'lodash/fp/unset';
import get from 'lodash/get';
import filter from 'lodash/filter';
import isEqual from 'lodash/isEqual';
Expand Down Expand Up @@ -285,11 +286,17 @@ export const coreReducer: Reducer<JsonFormsCore, CoreActions> = (
} else {
const oldData: any = get(state.data, action.path);
const newData = action.updater(cloneDeep(oldData));
const newState: any = setFp(
action.path,
newData,
state.data === undefined ? {} : state.data
);
let newState: any
if (newData !== undefined) {
newState = setFp(
action.path,
newData,
state.data === undefined ? {} : state.data
);
}
else {
newState = unsetFp(action.path, state.data === undefined ? {} : state.data);
}
const errors = validate(state.validator, newState);
return {
...state,
Expand Down

0 comments on commit 07ec766

Please sign in to comment.