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 BackgroundInputComponent from '../components/background-input';
import reducers from '../reducers'; import reducers from '../reducers';
import messages from '../content/messages'; 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); console.error('Vim-Vixen:', e);
if (sender) { if (sender) {
backgroundStore.dispatch(consoleActions.showError(e.message), sender); store.dispatch(consoleActions.showError(e.message), sender);
} }
}); });
const backgroundComponent = new BackgroundComponent(backgroundStore); const backgroundComponent = new BackgroundComponent(store);
const backgroundInputComponent = new BackgroundInputComponent(backgroundStore); const backgroundInputComponent = new BackgroundInputComponent(store);
backgroundStore.subscribe((sender) => { store.subscribe((sender) => {
backgroundComponent.update(sender); backgroundComponent.update(sender);
backgroundInputComponent.update(sender); backgroundInputComponent.update(sender);
}); });
backgroundStore.subscribe((sender) => { store.subscribe((sender) => {
if (sender) { if (sender) {
return browser.tabs.sendMessage(sender.tab.id, { return browser.tabs.sendMessage(sender.tab.id, {
type: messages.STATE_UPDATE, 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 scrolls from '../content/scrolls';
import * as navigates from '../content/navigates'; import * as navigates from '../content/navigates';
import * as followActions from '../actions/follow'; import * as followActions from '../actions/follow';
import * as store 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 followReducer from '../reducers/follow';
import operations from '../operations'; import operations from '../operations';
import messages from './messages'; import messages from './messages';
const followStore = store.createStore(followReducer); const store = createStore(followReducer);
const followComponent = new FollowComponent(window.document.body, followStore); const followComponent = new FollowComponent(window.document.body, store);
followStore.subscribe(() => { store.subscribe(() => {
try { try {
followComponent.update(); followComponent.update();
} catch (e) { } catch (e) {
@ -39,7 +39,7 @@ const execOperation = (operation) => {
case operations.SCROLL_END: case operations.SCROLL_END:
return scrolls.scrollRight(window); return scrolls.scrollRight(window);
case operations.FOLLOW_START: case operations.FOLLOW_START:
return followStore.dispatch(followActions.enable(false)); return store.dispatch(followActions.enable(false));
case operations.NAVIGATE_HISTORY_PREV: case operations.NAVIGATE_HISTORY_PREV:
return navigates.historyPrev(window); return navigates.historyPrev(window);
case operations.NAVIGATE_HISTORY_NEXT: case operations.NAVIGATE_HISTORY_NEXT:

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

@ -1,15 +1,15 @@
import './settings.scss'; import './settings.scss';
import SettingComponent from '../components/setting'; import SettingComponent from '../components/setting';
import settingReducer from '../reducers/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; let settingComponent = null;
settingStore.subscribe(() => { store.subscribe(() => {
settingComponent.update(); settingComponent.update();
}); });
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
settingComponent = new SettingComponent(document.body, settingStore); settingComponent = new SettingComponent(document.body, store);
}); });