-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreducers.js
52 lines (47 loc) · 1.32 KB
/
reducers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import initialState from './initialState';
import * as types from './actionTypes';
const utils = require('react-schema-form/lib/utils');
import omit from 'lodash/omit';
export default function reducer(state = initialState.schemaForm, action) {
switch (action.type) {
case types.SET_SCHEMA_FORM_DATA_VALID: {
const formData = Object.assign(
{},
state[action.formId],
{formIsValid: action.valid}
);
return Object.assign(
{},
state,
{[action.formId]: formData}
);
}
case types.SET_SCHEMA_FORM_DATA: {
const data = action.data; // Get the validation result
let formData = Object.assign(
{},
state[action.formId]
); // Get new data for this form instance
utils.selectOrSet(action.key, formData, data); // Set that form element's current value (if defined)
return Object.assign(
{},
state,
{[action.formId]: formData}
);
}
case types.CREATE_SCHEMA_FORM_STORE: {
const newState = {[action.formId]: action.initialModel || {}};
return Object.assign(
{},
state,
newState
);
}
case types.REMOVE_SCHEMA_FORM_STORE: {
// Removes only the formId key.
return omit(state, action.formId);
}
default:
return state;
}
}