-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreducer.js
More file actions
executable file
·40 lines (38 loc) · 1.02 KB
/
reducer.js
File metadata and controls
executable file
·40 lines (38 loc) · 1.02 KB
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
import _findIndex from 'lodash/findIndex';
import * as ActionTypes from './actions';
export default function (state, action) {
switch (action.type) {
case ActionTypes.REGISTERED_FORM_ELEMENT: {
return {
...state,
components: [
...state.components, { id: action.id, rules: action.rules }
]
};
}
case ActionTypes.FORM_ELEMENT_UPDATED: {
return {
...state,
values: {
...state.values, [action.id]: action.value
}
};
}
case ActionTypes.UNREGISTERED_FORM_ELEMENT: {
const index = _findIndex(state.components, c => c.id === action.id);
if (index > -1) {
return {
...state,
components: [...state.components.slice(0, index), ...state.components.slice(index + 1)]
};
}
return state;
}
case ActionTypes.FORM_VALIDATION_RESULT: {
return { ...state, invalid: action.invalid };
}
default: {
return state;
}
}
}