use createStore short-hand method

jh-changes
Shin'ya Ueoka 7 years ago
parent 482206f6c9
commit 6594841b1d
  1. 18
      src/background/index.js
  2. 10
      src/content/index.js
  3. 16
      src/pages/console.js
  4. 8
      src/pages/settings.js

@ -4,27 +4,27 @@ import BackgroundComponent from '../components/background';
import BackgroundInputComponent from '../components/background-input';
import reducers from '../reducers';
import messages from '../content/messages';
import * as store from '../store';
import { createStore } from '../store';
const backgroundStore = store.createStore(reducers, (e, sender) => {
const store = createStore(reducers, (e, sender) => {
console.error('Vim-Vixen:', e);
if (sender) {
backgroundStore.dispatch(consoleActions.showError(e.message), sender);
store.dispatch(consoleActions.showError(e.message), sender);
}
});
const backgroundComponent = new BackgroundComponent(backgroundStore);
const backgroundInputComponent = new BackgroundInputComponent(backgroundStore);
backgroundStore.subscribe((sender) => {
const backgroundComponent = new BackgroundComponent(store);
const backgroundInputComponent = new BackgroundInputComponent(store);
store.subscribe((sender) => {
backgroundComponent.update(sender);
backgroundInputComponent.update(sender);
});
backgroundStore.subscribe((sender) => {
store.subscribe((sender) => {
if (sender) {
return browser.tabs.sendMessage(sender.tab.id, {
type: messages.STATE_UPDATE,
state: backgroundStore.getState()
state: store.getState()
});
}
});
backgroundStore.dispatch(settingsActions.load());
store.dispatch(settingsActions.load());

@ -3,16 +3,16 @@ import * as consoleFrames from './console-frames';
import * as scrolls from '../content/scrolls';
import * as navigates from '../content/navigates';
import * as followActions from '../actions/follow';
import * as store from '../store';
import { createStore } from '../store';
import ContentInputComponent from '../components/content-input';
import FollowComponent from '../components/follow';
import followReducer from '../reducers/follow';
import operations from '../operations';
import messages from './messages';
const followStore = store.createStore(followReducer);
const followComponent = new FollowComponent(window.document.body, followStore);
followStore.subscribe(() => {
const store = createStore(followReducer);
const followComponent = new FollowComponent(window.document.body, store);
store.subscribe(() => {
try {
followComponent.update();
} catch (e) {
@ -39,7 +39,7 @@ const execOperation = (operation) => {
case operations.SCROLL_END:
return scrolls.scrollRight(window);
case operations.FOLLOW_START:
return followStore.dispatch(followActions.enable(false));
return store.dispatch(followActions.enable(false));
case operations.NAVIGATE_HISTORY_PREV:
return navigates.historyPrev(window);
case operations.NAVIGATE_HISTORY_NEXT:

@ -3,26 +3,26 @@ import messages from '../content/messages';
import CompletionComponent from '../components/completion';
import ConsoleComponent from '../components/console';
import completionReducer from '../reducers/completion';
import * as store from '../store';
import { createStore } from '../store';
import * as completionActions from '../actions/completion';
const completionStore = store.createStore(completionReducer);
const store = createStore(completionReducer);
let completionComponent = null;
let consoleComponent = null;
let prevState = {};
window.addEventListener('load', () => {
let wrapper = document.querySelector('#vimvixen-console-completion');
completionComponent = new CompletionComponent(wrapper, completionStore);
completionComponent = new CompletionComponent(wrapper, store);
// TODO use root root store instead of completionStore
consoleComponent = new ConsoleComponent(document.body, completionStore);
// TODO use root root store instead of store
consoleComponent = new ConsoleComponent(document.body, store);
});
completionStore.subscribe(() => {
store.subscribe(() => {
completionComponent.update();
let state = completionStore.getState();
let state = store.getState();
if (state.groupSelection >= 0) {
let item = state.groups[state.groupSelection].items[state.itemSelection];
@ -40,6 +40,6 @@ browser.runtime.onMessage.addListener((action) => {
if (action.type === messages.STATE_UPDATE) {
let state = action.state.console;
consoleComponent.update(state);
completionStore.dispatch(completionActions.setItems(state.completions));
store.dispatch(completionActions.setItems(state.completions));
}
});

@ -1,15 +1,15 @@
import './settings.scss';
import SettingComponent from '../components/setting';
import settingReducer from '../reducers/setting';
import * as store from '../store';
import { createStore } from '../store';
const settingStore = store.createStore(settingReducer);
const store = createStore(settingReducer);
let settingComponent = null;
settingStore.subscribe(() => {
store.subscribe(() => {
settingComponent.update();
});
document.addEventListener('DOMContentLoaded', () => {
settingComponent = new SettingComponent(document.body, settingStore);
settingComponent = new SettingComponent(document.body, store);
});