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
|
import * as actions from '../actions';
import {
JSONSettings, FormSettings, SettingSource,
} from '../../shared/SettingData';
export interface State {
source: SettingSource;
json?: JSONSettings;
form?: FormSettings;
error: string;
}
const defaultState: State = {
source: SettingSource.JSON,
json: JSONSettings.valueOf(''),
error: '',
};
export default function reducer(
state = defaultState,
action: actions.SettingAction,
): State {
switch (action.type) {
case actions.SETTING_SET_SETTINGS:
return { ...state,
source: action.source,
json: action.json,
form: action.form,
error: '', };
case actions.SETTING_SHOW_ERROR:
return { ...state,
error: action.error,
json: action.json, };
case actions.SETTING_SWITCH_TO_FORM:
return { ...state,
error: '',
source: SettingSource.Form,
form: action.form, };
case actions.SETTING_SWITCH_TO_JSON:
return { ...state,
error: '',
source: SettingSource.JSON,
json: action.json, };
default:
return state;
}
}
|