From 6594841b1d1f082107bdb1489f02d3c99cff8ffa Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Wed, 4 Oct 2017 21:30:57 +0900 Subject: use createStore short-hand method --- src/background/index.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/background') diff --git a/src/background/index.js b/src/background/index.js index e968c82..9a1adc6 100644 --- a/src/background/index.js +++ b/src/background/index.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()); -- cgit v1.2.3 From 32168a94e07478325a53779513533b76a6ef2c18 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Thu, 5 Oct 2017 20:14:58 +0900 Subject: fix imports in src --- src/actions/command.js | 4 ++-- src/actions/completion.js | 2 +- src/actions/console.js | 2 +- src/actions/follow.js | 2 +- src/actions/input.js | 2 +- src/actions/operation.js | 8 ++++---- src/actions/setting.js | 6 +++--- src/background/index.js | 14 +++++++------- src/components/background-input.js | 4 ++-- src/components/background.js | 12 ++++++------ src/components/console.js | 4 ++-- src/components/content-input.js | 2 +- src/components/follow.js | 8 ++++---- src/components/setting.js | 4 ++-- src/content/index.js | 16 ++++++++-------- src/pages/console.js | 12 ++++++------ src/pages/settings.js | 6 +++--- src/reducers/completion.js | 2 +- src/reducers/console.js | 2 +- src/reducers/follow.js | 2 +- src/reducers/index.js | 10 +++++----- src/reducers/input.js | 2 +- src/reducers/setting.js | 2 +- src/shared/validators/setting.js | 2 +- webpack.config.js | 2 +- 25 files changed, 66 insertions(+), 66 deletions(-) (limited to 'src/background') diff --git a/src/actions/command.js b/src/actions/command.js index f578afd..a40cc97 100644 --- a/src/actions/command.js +++ b/src/actions/command.js @@ -1,5 +1,5 @@ -import * as tabs from '../background/tabs'; -import * as histories from '../background/histories'; +import * as tabs from 'background/tabs'; +import * as histories from 'background/histories'; import * as consoleActions from './console'; const normalizeUrl = (string, searchConfig) => { diff --git a/src/actions/completion.js b/src/actions/completion.js index 1ffb025..733f516 100644 --- a/src/actions/completion.js +++ b/src/actions/completion.js @@ -1,4 +1,4 @@ -import actions from '../actions'; +import actions from 'actions'; const setItems = (groups) => { return { diff --git a/src/actions/console.js b/src/actions/console.js index e0ec631..ba1fbeb 100644 --- a/src/actions/console.js +++ b/src/actions/console.js @@ -1,4 +1,4 @@ -import actions from '../actions'; +import actions from 'actions'; const showCommand = (text) => { return { diff --git a/src/actions/follow.js b/src/actions/follow.js index 7ab689e..708cd95 100644 --- a/src/actions/follow.js +++ b/src/actions/follow.js @@ -1,4 +1,4 @@ -import actions from '../actions'; +import actions from 'actions'; const enable = (newTab) => { return { diff --git a/src/actions/input.js b/src/actions/input.js index 67788dd..61acb76 100644 --- a/src/actions/input.js +++ b/src/actions/input.js @@ -1,4 +1,4 @@ -import actions from '../actions'; +import actions from 'actions'; const asKeymapChars = (key, ctrl) => { if (ctrl) { diff --git a/src/actions/operation.js b/src/actions/operation.js index 3ed7f05..97bcf45 100644 --- a/src/actions/operation.js +++ b/src/actions/operation.js @@ -1,8 +1,8 @@ -import operations from '../shared/operations'; -import messages from '../content/messages'; +import operations from 'shared/operations'; +import messages from 'content/messages'; import * as consoleActions from './console'; -import * as tabs from '../background/tabs'; -import * as zooms from '../background/zooms'; +import * as tabs from 'background/tabs'; +import * as zooms from 'background/zooms'; const exec = (operation, tab) => { switch (operation.type) { diff --git a/src/actions/setting.js b/src/actions/setting.js index 7898f06..2a47608 100644 --- a/src/actions/setting.js +++ b/src/actions/setting.js @@ -1,6 +1,6 @@ -import actions from '../actions'; -import messages from '../content/messages'; -import DefaultSettings from '../shared/default-settings'; +import actions from 'actions'; +import messages from 'content/messages'; +import DefaultSettings from 'shared/default-settings'; const load = () => { return browser.storage.local.get('settings').then((value) => { diff --git a/src/background/index.js b/src/background/index.js index 9a1adc6..8dc55cb 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -1,10 +1,10 @@ -import * as consoleActions from '../actions/console'; -import * as settingsActions from '../actions/setting'; -import BackgroundComponent from '../components/background'; -import BackgroundInputComponent from '../components/background-input'; -import reducers from '../reducers'; -import messages from '../content/messages'; -import { createStore } from '../store'; +import * as consoleActions from 'actions/console'; +import * as settingsActions from 'actions/setting'; +import BackgroundComponent from 'components/background'; +import BackgroundInputComponent from 'components/background-input'; +import reducers from 'reducers'; +import messages from 'content/messages'; +import { createStore } from 'store'; const store = createStore(reducers, (e, sender) => { console.error('Vim-Vixen:', e); diff --git a/src/components/background-input.js b/src/components/background-input.js index 4735d5a..bd6ecf9 100644 --- a/src/components/background-input.js +++ b/src/components/background-input.js @@ -1,5 +1,5 @@ -import * as inputActions from '../actions/input'; -import * as operationActions from '../actions/operation'; +import * as inputActions from 'actions/input'; +import * as operationActions from 'actions/operation'; export default class BackgroundInputComponent { constructor(store) { diff --git a/src/components/background.js b/src/components/background.js index 0585a04..08d5115 100644 --- a/src/components/background.js +++ b/src/components/background.js @@ -1,9 +1,9 @@ -import messages from '../content/messages'; -import * as commandActions from '../actions/command'; -import * as consoleActions from '../actions/console'; -import * as inputActions from '../actions/input'; -import * as settingsActions from '../actions/setting'; -import * as tabActions from '../actions/tab'; +import messages from 'content/messages'; +import * as commandActions from 'actions/command'; +import * as consoleActions from 'actions/console'; +import * as inputActions from 'actions/input'; +import * as settingsActions from 'actions/setting'; +import * as tabActions from 'actions/tab'; export default class BackgroundComponent { constructor(store) { diff --git a/src/components/console.js b/src/components/console.js index 9580dcf..25b135c 100644 --- a/src/components/console.js +++ b/src/components/console.js @@ -1,5 +1,5 @@ -import messages from '../content/messages'; -import * as completionActions from '../actions/completion'; +import messages from 'content/messages'; +import * as completionActions from 'actions/completion'; export default class ConsoleComponent { constructor(wrapper, store) { diff --git a/src/components/content-input.js b/src/components/content-input.js index 10c785b..38d57fd 100644 --- a/src/components/content-input.js +++ b/src/components/content-input.js @@ -1,4 +1,4 @@ -import messages from '../content/messages'; +import messages from 'content/messages'; export default class ContentInputComponent { constructor(target) { diff --git a/src/components/follow.js b/src/components/follow.js index d2d3902..9221759 100644 --- a/src/components/follow.js +++ b/src/components/follow.js @@ -1,7 +1,7 @@ -import * as followActions from '../actions/follow'; -import messages from '../content/messages'; -import Hint from '../content/hint'; -import HintKeyProducer from '../content/hint-key-producer'; +import * as followActions from 'actions/follow'; +import messages from 'content/messages'; +import Hint from 'content/hint'; +import HintKeyProducer from 'content/hint-key-producer'; const DEFAULT_HINT_CHARSET = 'abcdefghijklmnopqrstuvwxyz'; diff --git a/src/components/setting.js b/src/components/setting.js index 1f3b3fe..c2f99b6 100644 --- a/src/components/setting.js +++ b/src/components/setting.js @@ -1,5 +1,5 @@ -import * as settingActions from '../actions/setting'; -import { validate } from '../shared/validators/setting'; +import * as settingActions from 'actions/setting'; +import { validate } from 'shared/validators/setting'; export default class SettingComponent { constructor(wrapper, store) { diff --git a/src/content/index.js b/src/content/index.js index a9a50be..31b37cf 100644 --- a/src/content/index.js +++ b/src/content/index.js @@ -1,13 +1,13 @@ import './console-frame.scss'; 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 { createStore } from '../store'; -import ContentInputComponent from '../components/content-input'; -import FollowComponent from '../components/follow'; -import reducers from '../reducers'; -import operations from '../shared/operations'; +import * as scrolls from 'content/scrolls'; +import * as navigates from 'content/navigates'; +import * as followActions from 'actions/follow'; +import { createStore } from 'store'; +import ContentInputComponent from 'components/content-input'; +import FollowComponent from 'components/follow'; +import reducers from 'reducers'; +import operations from 'shared/operations'; import messages from './messages'; const store = createStore(reducers); diff --git a/src/pages/console.js b/src/pages/console.js index 0e152d3..a4536ec 100644 --- a/src/pages/console.js +++ b/src/pages/console.js @@ -1,10 +1,10 @@ import './console.scss'; -import messages from '../content/messages'; -import CompletionComponent from '../components/completion'; -import ConsoleComponent from '../components/console'; -import reducers from '../reducers'; -import { createStore } from '../store'; -import * as completionActions from '../actions/completion'; +import messages from 'content/messages'; +import CompletionComponent from 'components/completion'; +import ConsoleComponent from 'components/console'; +import reducers from 'reducers'; +import { createStore } from 'store'; +import * as completionActions from 'actions/completion'; const store = createStore(reducers); let completionComponent = null; diff --git a/src/pages/settings.js b/src/pages/settings.js index 076d23d..6e25e6f 100644 --- a/src/pages/settings.js +++ b/src/pages/settings.js @@ -1,7 +1,7 @@ import './settings.scss'; -import SettingComponent from '../components/setting'; -import settingReducer from '../reducers/setting'; -import { createStore } from '../store'; +import SettingComponent from 'components/setting'; +import settingReducer from 'reducers/setting'; +import { createStore } from 'store'; const store = createStore(settingReducer); let settingComponent = null; diff --git a/src/reducers/completion.js b/src/reducers/completion.js index 878aeac..f85a500 100644 --- a/src/reducers/completion.js +++ b/src/reducers/completion.js @@ -1,4 +1,4 @@ -import actions from '../actions'; +import actions from 'actions'; const defaultState = { groupSelection: -1, diff --git a/src/reducers/console.js b/src/reducers/console.js index 5c49c3b..3e63672 100644 --- a/src/reducers/console.js +++ b/src/reducers/console.js @@ -1,4 +1,4 @@ -import actions from '../actions'; +import actions from 'actions'; const defaultState = { errorShown: false, diff --git a/src/reducers/follow.js b/src/reducers/follow.js index 136b367..a2397b4 100644 --- a/src/reducers/follow.js +++ b/src/reducers/follow.js @@ -1,4 +1,4 @@ -import actions from '../actions'; +import actions from 'actions'; const defaultState = { enabled: false, diff --git a/src/reducers/index.js b/src/reducers/index.js index db17edf..5a4f14b 100644 --- a/src/reducers/index.js +++ b/src/reducers/index.js @@ -1,8 +1,8 @@ -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'; +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, {}), diff --git a/src/reducers/input.js b/src/reducers/input.js index 8be701e..2e4bcd8 100644 --- a/src/reducers/input.js +++ b/src/reducers/input.js @@ -1,4 +1,4 @@ -import actions from '../actions'; +import actions from 'actions'; const defaultState = { keys: '', diff --git a/src/reducers/setting.js b/src/reducers/setting.js index 735d4fb..7326ed7 100644 --- a/src/reducers/setting.js +++ b/src/reducers/setting.js @@ -1,4 +1,4 @@ -import actions from '../actions'; +import actions from 'actions'; const defaultState = { settings: {} diff --git a/src/shared/validators/setting.js b/src/shared/validators/setting.js index 4dc35ff..5039ec2 100644 --- a/src/shared/validators/setting.js +++ b/src/shared/validators/setting.js @@ -1,4 +1,4 @@ -import operations from '../operations'; +import operations from 'shared/operations'; const VALID_TOP_KEYS = ['keymaps', 'search']; const VALID_OPERATION_VALUES = Object.keys(operations).map((key) => { diff --git a/webpack.config.js b/webpack.config.js index e4d5a17..3d4ef03 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -40,7 +40,7 @@ module.exports = { resolve: { extensions: [ '.js' ], - modules: [path.join(__dirname), 'node_modules'] + modules: [path.join(__dirname, 'src'), 'node_modules'] }, plugins: [ -- cgit v1.2.3 From 4cb17031d11d76275de51e31218fb87359e7d826 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Fri, 6 Oct 2017 23:55:52 +0900 Subject: [wip] remove STATE_UPDATE --- src/actions/operation.js | 20 +++++++++++++------- src/background/index.js | 9 --------- src/components/console.js | 4 ++-- src/content/index.js | 13 ++++--------- src/content/messages.js | 4 +++- src/pages/console.js | 13 +++++++++---- 6 files changed, 31 insertions(+), 32 deletions(-) (limited to 'src/background') diff --git a/src/actions/operation.js b/src/actions/operation.js index 97bcf45..295fd4f 100644 --- a/src/actions/operation.js +++ b/src/actions/operation.js @@ -1,9 +1,15 @@ import operations from 'shared/operations'; import messages from 'content/messages'; -import * as consoleActions from './console'; import * as tabs from 'background/tabs'; import * as zooms from 'background/zooms'; +const sendConsoleShowCommand = (tab, command) => { + return browser.tabs.sendMessage(tab.id, { + type: messages.CONSOLE_SHOW_COMMAND, + command, + }); +}; + const exec = (operation, tab) => { switch (operation.type) { case operations.TAB_CLOSE: @@ -23,21 +29,21 @@ const exec = (operation, tab) => { case operations.ZOOM_NEUTRAL: return zooms.neutral(); case operations.COMMAND_SHOW: - return consoleActions.showCommand(''); + return sendConsoleShowCommand(tab, ''); case operations.COMMAND_SHOW_OPEN: if (operation.alter) { // alter url - return consoleActions.showCommand('open ' + tab.url); + return sendConsoleShowCommand(tab, 'open ' + tab.url); } - return consoleActions.showCommand('open '); + return sendConsoleShowCommand(tab, 'open '); case operations.COMMAND_SHOW_TABOPEN: if (operation.alter) { // alter url - return consoleActions.showCommand('tabopen ' + tab.url); + return sendConsoleShowCommand(tab, 'tabopen ' + tab.url); } - return consoleActions.showCommand('tabopen '); + return sendConsoleShowCommand(tab, 'tabopen '); case operations.COMMAND_SHOW_BUFFER: - return consoleActions.showCommand('buffer '); + return sendConsoleShowCommand(tab, 'buffer '); default: return browser.tabs.sendMessage(tab.id, { type: messages.CONTENT_OPERATION, diff --git a/src/background/index.js b/src/background/index.js index 8dc55cb..05d3553 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -3,7 +3,6 @@ import * as settingsActions from 'actions/setting'; import BackgroundComponent from 'components/background'; import BackgroundInputComponent from 'components/background-input'; import reducers from 'reducers'; -import messages from 'content/messages'; import { createStore } from 'store'; const store = createStore(reducers, (e, sender) => { @@ -18,13 +17,5 @@ store.subscribe((sender) => { backgroundComponent.update(sender); backgroundInputComponent.update(sender); }); -store.subscribe((sender) => { - if (sender) { - return browser.tabs.sendMessage(sender.tab.id, { - type: messages.STATE_UPDATE, - state: store.getState() - }); - } -}); store.dispatch(settingsActions.load()); diff --git a/src/components/console.js b/src/components/console.js index 177cfe5..3a7f88b 100644 --- a/src/components/console.js +++ b/src/components/console.js @@ -70,8 +70,8 @@ export default class ConsoleComponent { }); } - // TODO use store/reducer to update state. - update(state) { + update() { + let state = this.store.getState().console; if (!this.prevState.commandShown && state.commandShown) { this.showCommand(state.commandText); } else if (!state.commandShown) { diff --git a/src/content/index.js b/src/content/index.js index 31b37cf..b29118d 100644 --- a/src/content/index.js +++ b/src/content/index.js @@ -55,17 +55,12 @@ const execOperation = (operation) => { } }; -const update = (state) => { - if (!state.console.commandShown) { - window.focus(); - consoleFrames.blur(window.document); - } -}; - browser.runtime.onMessage.addListener((action) => { switch (action.type) { - case messages.STATE_UPDATE: - return update(action.state); + case messages.CONSOLE_HIDE: + window.focus(); + consoleFrames.blur(window.document); + return Promise.resolve(); case messages.CONTENT_OPERATION: execOperation(action.operation); return Promise.resolve(); diff --git a/src/content/messages.js b/src/content/messages.js index 72a566b..0e66fa0 100644 --- a/src/content/messages.js +++ b/src/content/messages.js @@ -1,10 +1,12 @@ export default { - STATE_UPDATE: 'state.update', CONTENT_OPERATION: 'content.operation', CONSOLE_BLURRED: 'console.blured', CONSOLE_ENTERED: 'console.entered', CONSOLE_QUERY_COMPLETIONS: 'console.query.completions', + CONSOLE_SHOW_COMMAND: 'console.show.command', + CONSOLE_SHOW_ERROR: 'console.show.error', + CONSOLE_HIDE: 'console.hide', KEYDOWN: 'keydown', diff --git a/src/pages/console.js b/src/pages/console.js index 4d78826..4d3dd3f 100644 --- a/src/pages/console.js +++ b/src/pages/console.js @@ -4,7 +4,7 @@ import CompletionComponent from 'components/completion'; import ConsoleComponent from 'components/console'; import reducers from 'reducers'; import { createStore } from 'store'; -import * as completionActions from 'actions/completion'; +import * as consoleActions from 'actions/console'; const store = createStore(reducers); let completionComponent = null; @@ -20,6 +20,7 @@ window.addEventListener('load', () => { store.subscribe(() => { completionComponent.update(); + consoleComponent.update(); let state = store.getState().completion; @@ -36,8 +37,12 @@ store.subscribe(() => { }); browser.runtime.onMessage.addListener((action) => { - if (action.type === messages.STATE_UPDATE) { - let state = action.state.console; - consoleComponent.update(state); + switch (action.type) { + case messages.CONSOLE_SHOW_COMMAND: + return store.dispatch(consoleActions.showCommand(action.command)); + case messages.CONSOLE_SHOW_ERROR: + return store.dispatch(consoleActions.showError(action.command)); + case messages.CONSOLE_HIDE: + return store.dispatch(consoleActions.hide(action.command)); } }); -- cgit v1.2.3 From 9fb7bf96be786acfbad97f7c76bc423a401dd657 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sat, 7 Oct 2017 11:00:34 +0900 Subject: fix console errors --- src/background/index.js | 7 +++++-- src/components/background.js | 18 +++++++++++++----- src/pages/console.js | 2 +- 3 files changed, 19 insertions(+), 8 deletions(-) (limited to 'src/background') diff --git a/src/background/index.js b/src/background/index.js index 05d3553..b966c13 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -1,5 +1,5 @@ -import * as consoleActions from 'actions/console'; import * as settingsActions from 'actions/setting'; +import messages from 'content/messages'; import BackgroundComponent from 'components/background'; import BackgroundInputComponent from 'components/background-input'; import reducers from 'reducers'; @@ -8,7 +8,10 @@ import { createStore } from 'store'; const store = createStore(reducers, (e, sender) => { console.error('Vim-Vixen:', e); if (sender) { - store.dispatch(consoleActions.showError(e.message), sender); + return browser.tabs.sendMessage(sender.tab.id, { + type: messages.CONSOLE_SHOW_ERROR, + text: e.message, + }); } }); const backgroundComponent = new BackgroundComponent(store); diff --git a/src/components/background.js b/src/components/background.js index 195cfd9..487e3af 100644 --- a/src/components/background.js +++ b/src/components/background.js @@ -1,5 +1,4 @@ import messages from 'content/messages'; -import * as consoleActions from 'actions/console'; import * as inputActions from 'actions/input'; import * as settingsActions from 'actions/setting'; import * as tabActions from 'actions/tab'; @@ -14,7 +13,10 @@ export default class BackgroundComponent { try { return this.onMessage(message, sender); } catch (e) { - this.store.dispatch(consoleActions.showError(e.message), sender); + return browser.tabs.sendMessage(sender.tab.id, { + type: messages.CONSOLE_SHOW_ERROR, + text: e.message, + }); } }); } @@ -44,10 +46,16 @@ export default class BackgroundComponent { return this.store.dispatch( tabActions.openToTab(message.url, sender.tab), sender); case messages.CONSOLE_BLURRED: - return this.store.dispatch( - consoleActions.hide(), sender); + return browser.tabs.sendMessage(sender.tab.id, { + type: messages.CONSOLE_HIDE, + }); case messages.CONSOLE_ENTERED: - return commands.exec(message.text, this.settings); + return commands.exec(message.text, this.settings).catch((e) => { + return browser.tabs.sendMessage(sender.tab.id, { + type: messages.CONSOLE_SHOW_ERROR, + text: e.message, + }); + }); case messages.CONSOLE_QUERY_COMPLETIONS: return commands.complete(message.text, this.settings); case messages.SETTINGS_RELOAD: diff --git a/src/pages/console.js b/src/pages/console.js index 20a60f6..b7be73d 100644 --- a/src/pages/console.js +++ b/src/pages/console.js @@ -27,7 +27,7 @@ browser.runtime.onMessage.addListener((action) => { case messages.CONSOLE_SHOW_COMMAND: return store.dispatch(consoleActions.showCommand(action.command)); case messages.CONSOLE_SHOW_ERROR: - return store.dispatch(consoleActions.showError(action.command)); + return store.dispatch(consoleActions.showError(action.text)); case messages.CONSOLE_HIDE: return store.dispatch(consoleActions.hide(action.command)); } -- cgit v1.2.3