Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove state slice when set as undefined #2163

Merged
merged 7 commits into from
Jul 13, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading