From e8056d2a709df9c9c182382fc7a31795e4dc1c0f Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sat, 9 Sep 2017 22:07:27 +0900 Subject: console state as action/reducer in redux --- src/reducers/console.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/reducers/console.js (limited to 'src/reducers') 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; + } +} -- cgit v1.2.3