aboutsummaryrefslogtreecommitdiff
path: root/src/content/reducers
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/reducers')
-rw-r--r--src/content/reducers/follow.js32
-rw-r--r--src/content/reducers/index.js18
-rw-r--r--src/content/reducers/input.js20
3 files changed, 70 insertions, 0 deletions
diff --git a/src/content/reducers/follow.js b/src/content/reducers/follow.js
new file mode 100644
index 0000000..b7c0cf3
--- /dev/null
+++ b/src/content/reducers/follow.js
@@ -0,0 +1,32 @@
+import actions from 'content/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,
+ keys: '',
+ });
+ case actions.FOLLOW_DISABLE:
+ return Object.assign({}, state, {
+ enabled: false,
+ });
+ case actions.FOLLOW_KEY_PRESS:
+ return Object.assign({}, state, {
+ keys: state.keys + action.key,
+ });
+ case actions.FOLLOW_BACKSPACE:
+ return Object.assign({}, state, {
+ keys: state.keys.slice(0, -1),
+ });
+ default:
+ return state;
+ }
+}
diff --git a/src/content/reducers/index.js b/src/content/reducers/index.js
new file mode 100644
index 0000000..a62217f
--- /dev/null
+++ b/src/content/reducers/index.js
@@ -0,0 +1,18 @@
+import settingReducer from 'settings/reducers/setting';
+import inputReducer from './input';
+import followReducer from './follow';
+
+// Make setting reducer instead of re-use
+const defaultState = {
+ input: inputReducer(undefined, {}),
+ setting: settingReducer(undefined, {}),
+ follow: followReducer(undefined, {}),
+};
+
+export default function reducer(state = defaultState, action = {}) {
+ return Object.assign({}, state, {
+ input: inputReducer(state.input, action),
+ setting: settingReducer(state.setting, action),
+ follow: followReducer(state.follow, action),
+ });
+}
diff --git a/src/content/reducers/input.js b/src/content/reducers/input.js
new file mode 100644
index 0000000..802020f
--- /dev/null
+++ b/src/content/reducers/input.js
@@ -0,0 +1,20 @@
+import actions from 'content/actions';
+
+const defaultState = {
+ keys: '',
+};
+
+export default function reducer(state = defaultState, action = {}) {
+ switch (action.type) {
+ case actions.INPUT_KEY_PRESS:
+ return Object.assign({}, state, {
+ keys: state.keys + action.key
+ });
+ case actions.INPUT_CLEAR_KEYS:
+ return Object.assign({}, state, {
+ keys: '',
+ });
+ default:
+ return state;
+ }
+}