2017-06-26 22:27:55 +00:00
|
|
|
// @flow
|
2017-07-04 03:21:19 +00:00
|
|
|
import type {
|
|
|
|
ConfigAction,
|
|
|
|
ChangeNodeAction,
|
|
|
|
ChangeLanguageAction
|
|
|
|
} from 'actions/config';
|
2017-07-04 01:25:01 +00:00
|
|
|
import { languages, NODES } from '../config/data';
|
2017-04-14 06:25:01 +00:00
|
|
|
|
2017-06-26 22:27:55 +00:00
|
|
|
export type State = {
|
2017-07-02 05:49:06 +00:00
|
|
|
// FIXME
|
|
|
|
languageSelection: string,
|
|
|
|
nodeSelection: string
|
|
|
|
};
|
2017-04-14 06:25:01 +00:00
|
|
|
|
2017-07-05 22:09:58 +00:00
|
|
|
export const initialState: State = {
|
2017-07-04 03:21:19 +00:00
|
|
|
languageSelection: languages[0].sign,
|
|
|
|
nodeSelection: Object.keys(NODES)[0]
|
2017-07-02 05:49:06 +00:00
|
|
|
};
|
2017-04-14 06:25:01 +00:00
|
|
|
|
2017-07-04 01:25:01 +00:00
|
|
|
function changeLanguage(state: State, action: ChangeLanguageAction): State {
|
2017-07-04 03:21:19 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
languageSelection: action.value
|
|
|
|
};
|
2017-06-26 22:27:55 +00:00
|
|
|
}
|
|
|
|
|
2017-07-04 01:25:01 +00:00
|
|
|
function changeNode(state: State, action: ChangeNodeAction): State {
|
2017-07-04 03:21:19 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
nodeSelection: action.value
|
|
|
|
};
|
2017-04-14 06:25:01 +00:00
|
|
|
}
|
|
|
|
|
2017-07-04 03:21:19 +00:00
|
|
|
export function config(
|
|
|
|
state: State = initialState,
|
|
|
|
action: ConfigAction
|
|
|
|
): State {
|
2017-07-02 05:49:06 +00:00
|
|
|
switch (action.type) {
|
2017-07-04 03:21:19 +00:00
|
|
|
case 'CONFIG_LANGUAGE_CHANGE':
|
|
|
|
return changeLanguage(state, action);
|
|
|
|
case 'CONFIG_NODE_CHANGE':
|
|
|
|
return changeNode(state, action);
|
2017-07-02 05:49:06 +00:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
2017-04-14 06:25:01 +00:00
|
|
|
}
|