single reducer
This commit is contained in:
parent
6594841b1d
commit
79a4a805f6
6 changed files with 14 additions and 9 deletions
|
@ -6,7 +6,7 @@ export default class Completion {
|
||||||
}
|
}
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
let state = this.store.getState();
|
let state = this.store.getState().completion;
|
||||||
if (JSON.stringify(this.prevState) === JSON.stringify(state)) {
|
if (JSON.stringify(this.prevState) === JSON.stringify(state)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,7 @@ export default class FollowComponent {
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
let prevState = this.state;
|
let prevState = this.state;
|
||||||
this.state = this.store.getState();
|
this.state = this.store.getState().follow;
|
||||||
if (!prevState.enabled && this.state.enabled) {
|
if (!prevState.enabled && this.state.enabled) {
|
||||||
this.create();
|
this.create();
|
||||||
} else if (prevState.enabled && !this.state.enabled) {
|
} else if (prevState.enabled && !this.state.enabled) {
|
||||||
|
|
|
@ -6,11 +6,11 @@ import * as followActions from '../actions/follow';
|
||||||
import { createStore } from '../store';
|
import { createStore } from '../store';
|
||||||
import ContentInputComponent from '../components/content-input';
|
import ContentInputComponent from '../components/content-input';
|
||||||
import FollowComponent from '../components/follow';
|
import FollowComponent from '../components/follow';
|
||||||
import followReducer from '../reducers/follow';
|
import reducers from '../reducers';
|
||||||
import operations from '../operations';
|
import operations from '../operations';
|
||||||
import messages from './messages';
|
import messages from './messages';
|
||||||
|
|
||||||
const store = createStore(followReducer);
|
const store = createStore(reducers);
|
||||||
const followComponent = new FollowComponent(window.document.body, store);
|
const followComponent = new FollowComponent(window.document.body, store);
|
||||||
store.subscribe(() => {
|
store.subscribe(() => {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -2,11 +2,11 @@ import './console.scss';
|
||||||
import messages from '../content/messages';
|
import messages from '../content/messages';
|
||||||
import CompletionComponent from '../components/completion';
|
import CompletionComponent from '../components/completion';
|
||||||
import ConsoleComponent from '../components/console';
|
import ConsoleComponent from '../components/console';
|
||||||
import completionReducer from '../reducers/completion';
|
import reducers from '../reducers';
|
||||||
import { createStore } from '../store';
|
import { createStore } from '../store';
|
||||||
import * as completionActions from '../actions/completion';
|
import * as completionActions from '../actions/completion';
|
||||||
|
|
||||||
const store = createStore(completionReducer);
|
const store = createStore(reducers);
|
||||||
let completionComponent = null;
|
let completionComponent = null;
|
||||||
let consoleComponent = null;
|
let consoleComponent = null;
|
||||||
let prevState = {};
|
let prevState = {};
|
||||||
|
@ -15,14 +15,13 @@ window.addEventListener('load', () => {
|
||||||
let wrapper = document.querySelector('#vimvixen-console-completion');
|
let wrapper = document.querySelector('#vimvixen-console-completion');
|
||||||
completionComponent = new CompletionComponent(wrapper, store);
|
completionComponent = new CompletionComponent(wrapper, store);
|
||||||
|
|
||||||
// TODO use root root store instead of store
|
|
||||||
consoleComponent = new ConsoleComponent(document.body, store);
|
consoleComponent = new ConsoleComponent(document.body, store);
|
||||||
});
|
});
|
||||||
|
|
||||||
store.subscribe(() => {
|
store.subscribe(() => {
|
||||||
completionComponent.update();
|
completionComponent.update();
|
||||||
|
|
||||||
let state = store.getState();
|
let state = store.getState().completion;
|
||||||
|
|
||||||
if (state.groupSelection >= 0) {
|
if (state.groupSelection >= 0) {
|
||||||
let item = state.groups[state.groupSelection].items[state.itemSelection];
|
let item = state.groups[state.groupSelection].items[state.itemSelection];
|
||||||
|
|
|
@ -63,6 +63,6 @@ export default function reducer(state = defaultState, action = {}) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return defaultState;
|
return state;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
import inputReducer from '../reducers/input';
|
import inputReducer from '../reducers/input';
|
||||||
import consoleReducer from '../reducers/console';
|
import consoleReducer from '../reducers/console';
|
||||||
import settingReducer from '../reducers/setting';
|
import settingReducer from '../reducers/setting';
|
||||||
|
import followReducer from '../reducers/follow';
|
||||||
|
import completionReducer from '../reducers/completion';
|
||||||
|
|
||||||
const defaultState = {
|
const defaultState = {
|
||||||
input: inputReducer(undefined, {}),
|
input: inputReducer(undefined, {}),
|
||||||
console: consoleReducer(undefined, {}),
|
console: consoleReducer(undefined, {}),
|
||||||
setting: settingReducer(undefined, {}),
|
setting: settingReducer(undefined, {}),
|
||||||
|
follow: followReducer(undefined, {}),
|
||||||
|
completion: completionReducer(undefined, {}),
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function reducer(state = defaultState, action = {}) {
|
export default function reducer(state = defaultState, action = {}) {
|
||||||
|
@ -13,5 +17,7 @@ export default function reducer(state = defaultState, action = {}) {
|
||||||
input: inputReducer(state.input, action),
|
input: inputReducer(state.input, action),
|
||||||
console: consoleReducer(state.console, action),
|
console: consoleReducer(state.console, action),
|
||||||
setting: settingReducer(state.setting, action),
|
setting: settingReducer(state.setting, action),
|
||||||
|
follow: followReducer(state.follow, action),
|
||||||
|
completion: completionReducer(state.completion, action),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue