diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-09-09 22:07:27 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-09-09 22:31:54 +0900 |
commit | e8056d2a709df9c9c182382fc7a31795e4dc1c0f (patch) | |
tree | 88bd6e0fe572138941e0986c11deeebd788370a7 /src/reducers | |
parent | 8593b3f5cd0992dd250f5a845c19dc60bbb0bc91 (diff) |
console state as action/reducer in redux
Diffstat (limited to 'src/reducers')
-rw-r--r-- | src/reducers/console.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/reducers/console.js b/src/reducers/console.js new file mode 100644 index 0000000..62fc951 --- /dev/null +++ b/src/reducers/console.js @@ -0,0 +1,39 @@ +import actions from '../actions'; + +export const defaultState = { + errorText: '', + errorShown: false, + commandText: '', + commandShown: false, + completions: [], +}; + +export default function reducer(state = defaultState, action = {}) { + switch (action.type) { + case actions.CONSOLE_SHOW_COMMAND: + return Object.assign({}, state, { + commandShown: true, + commandText: action.text, + errorShow: false, + completions: [] + }); + case actions.CONSOLE_SET_COMPLETIONS: + return Object.assign({}, state, { + completions: action.completions + }); + case actions.CONSOLE_SHOW_ERROR: + return Object.assign({}, state, { + errorText: action.message, + errorShow: true, + commandShown: false, + }); + case actions.CONSOLE_HIDE: + return Object.assign({}, state, { + errorShown: false, + commandShown: false + + }); + default: + return state; + } +} |