MyCrypto/common/reducers/config.js

47 lines
952 B
JavaScript
Raw Normal View History

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-06-26 22:27:55 +00:00
export type State = {
2017-07-02 05:49:06 +00:00
// FIXME
languageSelection: string,
nodeSelection: string
};
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-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-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;
}
}