From 0a7ae631cd72100abdc26b84b06006bb5b166cba Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Mon, 2 Oct 2017 21:35:52 +0900 Subject: follow as redux --- src/reducers/follow.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/reducers/follow.js (limited to 'src/reducers') diff --git a/src/reducers/follow.js b/src/reducers/follow.js new file mode 100644 index 0000000..136b367 --- /dev/null +++ b/src/reducers/follow.js @@ -0,0 +1,31 @@ +import actions from '../actions'; + +const defaultState = { + enabled: false, + newTab: false, + keys: [], +}; + +export default function reducer(state = defaultState, action = {}) { + switch (action.type) { + case actions.FOLLOW_ENABLE: + return Object.assign({}, state, { + enabled: true, + newTab: action.newTab, + }); + case actions.FOLLOW_DISABLE: + return Object.assign({}, state, { + enabled: false, + }); + case actions.FOLLOW_KEY_PRESS: + return Object.assign({}, state, { + keys: state.keys.concat([action.key]), + }); + case actions.FOLLOW_BACKSPACE: + return Object.assign({}, state, { + keys: state.keys.slice(0, -1), + }); + default: + return state; + } +} -- cgit v1.2.3