single reducer

jh-changes
Shin'ya Ueoka 7 years ago
parent 6594841b1d
commit 79a4a805f6
  1. 2
      src/components/completion.js
  2. 2
      src/components/follow.js
  3. 4
      src/content/index.js
  4. 7
      src/pages/console.js
  5. 2
      src/reducers/completion.js
  6. 6
      src/reducers/index.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;
}

@ -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) {

@ -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 {

@ -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];

@ -63,6 +63,6 @@ export default function reducer(state = defaultState, action = {}) {
});
}
default:
return defaultState;
return state;
}
}

@ -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),
});
}