From 79a4a805f6be14572b4486ddb79b0ebb98e37690 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Wed, 4 Oct 2017 22:01:16 +0900 Subject: [PATCH] single reducer --- src/components/completion.js | 2 +- src/components/follow.js | 2 +- src/content/index.js | 4 ++-- src/pages/console.js | 7 +++---- src/reducers/completion.js | 2 +- src/reducers/index.js | 6 ++++++ 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/components/completion.js b/src/components/completion.js index 489061c..d1fdd06 100644 --- a/src/components/completion.js +++ b/src/components/completion.js @@ -6,7 +6,7 @@ export default class Completion { } update() { - let state = this.store.getState(); + let state = this.store.getState().completion; if (JSON.stringify(this.prevState) === JSON.stringify(state)) { return; } diff --git a/src/components/follow.js b/src/components/follow.js index 4fe4c58..d2d3902 100644 --- a/src/components/follow.js +++ b/src/components/follow.js @@ -44,7 +44,7 @@ export default class FollowComponent { update() { let prevState = this.state; - this.state = this.store.getState(); + this.state = this.store.getState().follow; if (!prevState.enabled && this.state.enabled) { this.create(); } else if (prevState.enabled && !this.state.enabled) { diff --git a/src/content/index.js b/src/content/index.js index ea08982..38ad837 100644 --- a/src/content/index.js +++ b/src/content/index.js @@ -6,11 +6,11 @@ import * as followActions from '../actions/follow'; import { createStore } from '../store'; import ContentInputComponent from '../components/content-input'; import FollowComponent from '../components/follow'; -import followReducer from '../reducers/follow'; +import reducers from '../reducers'; import operations from '../operations'; import messages from './messages'; -const store = createStore(followReducer); +const store = createStore(reducers); const followComponent = new FollowComponent(window.document.body, store); store.subscribe(() => { try { diff --git a/src/pages/console.js b/src/pages/console.js index 4ce9e47..0e152d3 100644 --- a/src/pages/console.js +++ b/src/pages/console.js @@ -2,11 +2,11 @@ import './console.scss'; import messages from '../content/messages'; import CompletionComponent from '../components/completion'; import ConsoleComponent from '../components/console'; -import completionReducer from '../reducers/completion'; +import reducers from '../reducers'; import { createStore } from '../store'; import * as completionActions from '../actions/completion'; -const store = createStore(completionReducer); +const store = createStore(reducers); let completionComponent = null; let consoleComponent = null; let prevState = {}; @@ -15,14 +15,13 @@ window.addEventListener('load', () => { let wrapper = document.querySelector('#vimvixen-console-completion'); completionComponent = new CompletionComponent(wrapper, store); - // TODO use root root store instead of store consoleComponent = new ConsoleComponent(document.body, store); }); store.subscribe(() => { completionComponent.update(); - let state = store.getState(); + let state = store.getState().completion; if (state.groupSelection >= 0) { let item = state.groups[state.groupSelection].items[state.itemSelection]; diff --git a/src/reducers/completion.js b/src/reducers/completion.js index a8a6444..878aeac 100644 --- a/src/reducers/completion.js +++ b/src/reducers/completion.js @@ -63,6 +63,6 @@ export default function reducer(state = defaultState, action = {}) { }); } default: - return defaultState; + return state; } } diff --git a/src/reducers/index.js b/src/reducers/index.js index 9beb81c..db17edf 100644 --- a/src/reducers/index.js +++ b/src/reducers/index.js @@ -1,11 +1,15 @@ import inputReducer from '../reducers/input'; import consoleReducer from '../reducers/console'; import settingReducer from '../reducers/setting'; +import followReducer from '../reducers/follow'; +import completionReducer from '../reducers/completion'; const defaultState = { input: inputReducer(undefined, {}), console: consoleReducer(undefined, {}), setting: settingReducer(undefined, {}), + follow: followReducer(undefined, {}), + completion: completionReducer(undefined, {}), }; export default function reducer(state = defaultState, action = {}) { @@ -13,5 +17,7 @@ export default function reducer(state = defaultState, action = {}) { input: inputReducer(state.input, action), console: consoleReducer(state.console, action), setting: settingReducer(state.setting, action), + follow: followReducer(state.follow, action), + completion: completionReducer(state.completion, action), }); }