blob: 6aba49989b722af4beeb6a64b293bba88ce1e781 (
plain)
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
|
export const OPTION_UPDATE_START = 'UI_OPTION_UPDATE_START'
export const OPTION_UPDATE_SUCCESS = 'UI_OPTION_UPDATE_SUCCESS'
export const OPTION_UPDATE_ERROR = 'UI_OPTION_UPDATE_ERROR'
const defaultState = {
/* optionName -> {isUpdating, value (client-side), error} */
}
export default function reducer(state = defaultState, action) {
switch (action.type) {
case OPTION_UPDATE_START:
return {
...state,
[action.option]: {
isUpdate: true,
value: action.value,
error: false,
}
}
case OPTION_UPDATE_SUCCESS:
let s = {...state}
delete s[action.option]
return s
case OPTION_UPDATE_ERROR:
return {
...state,
[action.option]: {
...state[action.option],
isUpdating: false,
error: action.error
}
}
default:
return state
}
}
|