From 22db12f2a37529a560eda1839c3a23011f900fab Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 8 Oct 2017 13:58:01 +0900 Subject: [PATCH 1/7] move messages to shared --- src/actions/operation.js | 2 +- src/actions/setting.js | 2 +- src/background/index.js | 2 +- src/components/background.js | 2 +- src/components/console.js | 2 +- src/components/follow.js | 2 +- src/content/index.js | 2 +- src/pages/console.js | 2 +- src/{content => shared}/messages.js | 0 9 files changed, 8 insertions(+), 8 deletions(-) rename src/{content => shared}/messages.js (100%) diff --git a/src/actions/operation.js b/src/actions/operation.js index 0bb8310..8b1590b 100644 --- a/src/actions/operation.js +++ b/src/actions/operation.js @@ -1,5 +1,5 @@ import operations from 'shared/operations'; -import messages from 'content/messages'; +import messages from 'shared/messages'; import * as tabs from 'background/tabs'; import * as zooms from 'background/zooms'; import * as scrolls from 'content/scrolls'; diff --git a/src/actions/setting.js b/src/actions/setting.js index 2a47608..c241428 100644 --- a/src/actions/setting.js +++ b/src/actions/setting.js @@ -1,5 +1,5 @@ import actions from 'actions'; -import messages from 'content/messages'; +import messages from 'shared/messages'; import DefaultSettings from 'shared/default-settings'; const load = () => { diff --git a/src/background/index.js b/src/background/index.js index dbc10fb..63d13cb 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -1,5 +1,5 @@ import * as settingsActions from 'actions/setting'; -import messages from 'content/messages'; +import messages from 'shared/messages'; import BackgroundComponent from 'components/background'; import reducers from 'reducers'; import { createStore } from 'store'; diff --git a/src/components/background.js b/src/components/background.js index 4961d85..afb90c2 100644 --- a/src/components/background.js +++ b/src/components/background.js @@ -1,4 +1,4 @@ -import messages from 'content/messages'; +import messages from 'shared/messages'; import * as operationActions from 'actions/operation'; import * as settingsActions from 'actions/setting'; import * as tabActions from 'actions/tab'; diff --git a/src/components/console.js b/src/components/console.js index 12341c1..20d15c2 100644 --- a/src/components/console.js +++ b/src/components/console.js @@ -1,4 +1,4 @@ -import messages from 'content/messages'; +import messages from 'shared/messages'; import * as consoleActions from 'actions/console'; export default class ConsoleComponent { diff --git a/src/components/follow.js b/src/components/follow.js index eedbd4d..0ec1e87 100644 --- a/src/components/follow.js +++ b/src/components/follow.js @@ -1,5 +1,5 @@ import * as followActions from 'actions/follow'; -import messages from 'content/messages'; +import messages from 'shared/messages'; import Hint from 'content/hint'; import HintKeyProducer from 'content/hint-key-producer'; diff --git a/src/content/index.js b/src/content/index.js index d380291..25a2e74 100644 --- a/src/content/index.js +++ b/src/content/index.js @@ -6,7 +6,7 @@ import ContentInputComponent from 'components/content-input'; import KeymapperComponent from 'components/keymapper'; import FollowComponent from 'components/follow'; import reducers from 'reducers'; -import messages from './messages'; +import messages from 'shared/messages'; const store = createStore(reducers); const followComponent = new FollowComponent(window.document.body, store); diff --git a/src/pages/console.js b/src/pages/console.js index b7be73d..4c6e16c 100644 --- a/src/pages/console.js +++ b/src/pages/console.js @@ -1,5 +1,5 @@ import './console.scss'; -import messages from 'content/messages'; +import messages from 'shared/messages'; import CompletionComponent from 'components/completion'; import ConsoleComponent from 'components/console'; import reducers from 'reducers'; diff --git a/src/content/messages.js b/src/shared/messages.js similarity index 100% rename from src/content/messages.js rename to src/shared/messages.js From 541449b1fced9eea15f415b023206b10724f5315 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 8 Oct 2017 14:18:12 +0900 Subject: [PATCH 2/7] separate console --- src/actions/index.js | 8 ----- src/{ => console}/actions/console.js | 2 +- src/console/actions/index.js | 9 ++++++ src/{ => console}/components/completion.js | 2 +- src/{ => console}/components/console.js | 4 +-- .../console.html => console/index.html} | 0 src/{pages/console.js => console/index.js} | 10 +++---- .../console.js => console/reducers/index.js} | 2 +- src/{pages/console.scss => console/site.scss} | 0 src/reducers/index.js | 3 -- test/{ => console}/actions/console.test.js | 4 +-- test/{ => console}/reducers/console.test.js | 30 +++++++++---------- webpack.config.js | 4 +-- 13 files changed, 38 insertions(+), 40 deletions(-) rename src/{ => console}/actions/console.js (94%) create mode 100644 src/console/actions/index.js rename src/{ => console}/components/completion.js (97%) rename src/{ => console}/components/console.js (97%) rename src/{pages/console.html => console/index.html} (100%) rename src/{pages/console.js => console/index.js} (78%) rename src/{reducers/console.js => console/reducers/index.js} (98%) rename src/{pages/console.scss => console/site.scss} (100%) rename test/{ => console}/actions/console.test.js (94%) rename test/{ => console}/reducers/console.test.js (83%) diff --git a/src/actions/index.js b/src/actions/index.js index 6a64795..0b3749d 100644 --- a/src/actions/index.js +++ b/src/actions/index.js @@ -1,12 +1,4 @@ export default { - // console commands - CONSOLE_SHOW_COMMAND: 'console.show.command', - CONSOLE_SET_COMPLETIONS: 'console.set.completions', - CONSOLE_SHOW_ERROR: 'console.show.error', - CONSOLE_HIDE: 'console.hide', - CONSOLE_COMPLETION_NEXT: 'console.completion.next', - CONSOLE_COMPLETION_PREV: 'console.completion.prev', - // User input INPUT_KEY_PRESS: 'input.key,press', INPUT_CLEAR_KEYS: 'input.clear.keys', diff --git a/src/actions/console.js b/src/console/actions/console.js similarity index 94% rename from src/actions/console.js rename to src/console/actions/console.js index 4183489..01d9a9b 100644 --- a/src/actions/console.js +++ b/src/console/actions/console.js @@ -1,4 +1,4 @@ -import actions from 'actions'; +import actions from 'console/actions'; const showCommand = (text) => { return { diff --git a/src/console/actions/index.js b/src/console/actions/index.js new file mode 100644 index 0000000..a5d03bc --- /dev/null +++ b/src/console/actions/index.js @@ -0,0 +1,9 @@ +export default { + // console commands + CONSOLE_SHOW_COMMAND: 'console.show.command', + CONSOLE_SET_COMPLETIONS: 'console.set.completions', + CONSOLE_SHOW_ERROR: 'console.show.error', + CONSOLE_HIDE: 'console.hide', + CONSOLE_COMPLETION_NEXT: 'console.completion.next', + CONSOLE_COMPLETION_PREV: 'console.completion.prev', +}; diff --git a/src/components/completion.js b/src/console/components/completion.js similarity index 97% rename from src/components/completion.js rename to src/console/components/completion.js index f527a84..5033b5c 100644 --- a/src/components/completion.js +++ b/src/console/components/completion.js @@ -6,7 +6,7 @@ export default class Completion { } update() { - let state = this.store.getState().console; + let state = this.store.getState(); if (JSON.stringify(this.prevState) === JSON.stringify(state)) { return; } diff --git a/src/components/console.js b/src/console/components/console.js similarity index 97% rename from src/components/console.js rename to src/console/components/console.js index 20d15c2..9023d91 100644 --- a/src/components/console.js +++ b/src/console/components/console.js @@ -1,5 +1,5 @@ import messages from 'shared/messages'; -import * as consoleActions from 'actions/console'; +import * as consoleActions from 'console/actions/console'; export default class ConsoleComponent { constructor(wrapper, store) { @@ -71,7 +71,7 @@ export default class ConsoleComponent { } update() { - let state = this.store.getState().console; + let state = this.store.getState(); if (!this.prevState.commandShown && state.commandShown) { this.showCommand(state.commandText); } else if (!state.commandShown) { diff --git a/src/pages/console.html b/src/console/index.html similarity index 100% rename from src/pages/console.html rename to src/console/index.html diff --git a/src/pages/console.js b/src/console/index.js similarity index 78% rename from src/pages/console.js rename to src/console/index.js index 4c6e16c..1bcf8bc 100644 --- a/src/pages/console.js +++ b/src/console/index.js @@ -1,10 +1,10 @@ -import './console.scss'; +import './site.scss'; import messages from 'shared/messages'; -import CompletionComponent from 'components/completion'; -import ConsoleComponent from 'components/console'; -import reducers from 'reducers'; +import CompletionComponent from 'console/components/completion'; +import ConsoleComponent from 'console/components/console'; +import reducers from 'console/reducers'; import { createStore } from 'store'; -import * as consoleActions from 'actions/console'; +import * as consoleActions from 'console/actions/console'; const store = createStore(reducers); let completionComponent = null; diff --git a/src/reducers/console.js b/src/console/reducers/index.js similarity index 98% rename from src/reducers/console.js rename to src/console/reducers/index.js index b9ed5b8..ee9c691 100644 --- a/src/reducers/console.js +++ b/src/console/reducers/index.js @@ -1,4 +1,4 @@ -import actions from 'actions'; +import actions from 'console/actions'; const defaultState = { errorShown: false, diff --git a/src/pages/console.scss b/src/console/site.scss similarity index 100% rename from src/pages/console.scss rename to src/console/site.scss diff --git a/src/reducers/index.js b/src/reducers/index.js index 8ed6452..3ebe491 100644 --- a/src/reducers/index.js +++ b/src/reducers/index.js @@ -1,11 +1,9 @@ import inputReducer from 'reducers/input'; -import consoleReducer from 'reducers/console'; import settingReducer from 'reducers/setting'; import followReducer from 'reducers/follow'; const defaultState = { input: inputReducer(undefined, {}), - console: consoleReducer(undefined, {}), setting: settingReducer(undefined, {}), follow: followReducer(undefined, {}), }; @@ -13,7 +11,6 @@ const defaultState = { export default function reducer(state = defaultState, action = {}) { return Object.assign({}, state, { input: inputReducer(state.input, action), - console: consoleReducer(state.console, action), setting: settingReducer(state.setting, action), follow: followReducer(state.follow, action), }); diff --git a/test/actions/console.test.js b/test/console/actions/console.test.js similarity index 94% rename from test/actions/console.test.js rename to test/console/actions/console.test.js index ff905bc..dd04c85 100644 --- a/test/actions/console.test.js +++ b/test/console/actions/console.test.js @@ -1,6 +1,6 @@ import { expect } from "chai"; -import actions from 'actions'; -import * as consoleActions from 'actions/console'; +import actions from 'console/actions'; +import * as consoleActions from 'console/actions/console'; describe("console actions", () => { describe("showCommand", () => { diff --git a/test/reducers/console.test.js b/test/console/reducers/console.test.js similarity index 83% rename from test/reducers/console.test.js rename to test/console/reducers/console.test.js index 5ebf4bc..95ac993 100644 --- a/test/reducers/console.test.js +++ b/test/console/reducers/console.test.js @@ -1,10 +1,10 @@ import { expect } from "chai"; -import actions from 'actions'; -import consoleReducer from 'reducers/console'; +import actions from 'console/actions'; +import reducer from 'console/reducers'; describe("console reducer", () => { it('return the initial state', () => { - let state = consoleReducer(undefined, {}); + let state = reducer(undefined, {}); expect(state).to.have.property('errorShown', false); expect(state).to.have.property('errorText', ''); expect(state).to.have.property('commandShown', false); @@ -16,7 +16,7 @@ describe("console reducer", () => { it('return next state for CONSOLE_SHOW_COMMAND', () => { let action = { type: actions.CONSOLE_SHOW_COMMAND, text: 'open ' }; - let state = consoleReducer({}, action); + let state = reducer({}, action); expect(state).to.have.property('commandShown', true); expect(state).to.have.property('commandText', 'open '); expect(state).to.have.property('errorShown', false); @@ -24,7 +24,7 @@ describe("console reducer", () => { it('return next state for CONSOLE_SHOW_ERROR', () => { let action = { type: actions.CONSOLE_SHOW_ERROR, text: 'an error' }; - let state = consoleReducer({}, action); + let state = reducer({}, action); expect(state).to.have.property('errorShown', true); expect(state).to.have.property('errorText', 'an error'); expect(state).to.have.property('commandShown', false); @@ -32,7 +32,7 @@ describe("console reducer", () => { it('return next state for CONSOLE_HIDE', () => { let action = { type: actions.CONSOLE_HIDE }; - let state = consoleReducer({}, action); + let state = reducer({}, action); expect(state).to.have.property('errorShown', false); expect(state).to.have.property('commandShown', false); }); @@ -53,7 +53,7 @@ describe("console reducer", () => { items: [4, 5, 6] }] } - state = consoleReducer(state, action); + state = reducer(state, action); expect(state).to.have.property('completions', action.completions); expect(state).to.have.property('groupSelection', -1); expect(state).to.have.property('itemSelection', -1); @@ -73,16 +73,16 @@ describe("console reducer", () => { }] }; - state = consoleReducer(state, action); + state = reducer(state, action); expect(state).to.have.property('groupSelection', 0); expect(state).to.have.property('itemSelection', 0); - state = consoleReducer(state, action); + state = reducer(state, action); expect(state).to.have.property('groupSelection', 0); expect(state).to.have.property('itemSelection', 1); - state = consoleReducer(state, action); - state = consoleReducer(state, action); + state = reducer(state, action); + state = reducer(state, action); expect(state).to.have.property('groupSelection', -1); expect(state).to.have.property('itemSelection', -1); }); @@ -101,16 +101,16 @@ describe("console reducer", () => { }] }; - state = consoleReducer(state, action); + state = reducer(state, action); expect(state).to.have.property('groupSelection', 1); expect(state).to.have.property('itemSelection', 0); - state = consoleReducer(state, action); + state = reducer(state, action); expect(state).to.have.property('groupSelection', 0); expect(state).to.have.property('itemSelection', 1); - state = consoleReducer(state, action); - state = consoleReducer(state, action); + state = reducer(state, action); + state = reducer(state, action); expect(state).to.have.property('groupSelection', -1); expect(state).to.have.property('itemSelection', -1); }); diff --git a/webpack.config.js b/webpack.config.js index 3d4ef03..486814a 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -9,7 +9,7 @@ module.exports = { index: path.join(src, 'content'), settings: path.join(src, 'pages/settings'), background: path.join(src, 'background'), - console: path.join(src, 'pages', 'console.js') + console: path.join(src, 'console') }, output: { @@ -45,7 +45,7 @@ module.exports = { plugins: [ new HtmlWebpackPlugin({ - template: path.join(src, 'pages', 'console.html'), + template: path.join(src, 'console', 'index.html'), filename: path.join(dist, 'console.html'), inject: false }), From 58123210ab4cdd4a1f2b4720a0abbd88908baa06 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 8 Oct 2017 14:44:21 +0900 Subject: [PATCH 3/7] separate settings --- src/background/index.js | 2 +- src/components/background.js | 2 +- src/content/index.js | 2 +- src/reducers/index.js | 3 ++- src/settings/actions/index.js | 4 ++++ src/{ => settings}/actions/setting.js | 2 +- src/{ => settings}/components/setting.js | 2 +- .../settings.html => settings/index.html} | 0 src/{pages/settings.js => settings/index.js} | 6 ++--- src/{ => settings}/reducers/setting.js | 2 +- .../settings.scss => settings/site.scss} | 0 test/reducers/setting.test.js | 22 ------------------- webpack.config.js | 4 ++-- 13 files changed, 17 insertions(+), 34 deletions(-) create mode 100644 src/settings/actions/index.js rename src/{ => settings}/actions/setting.js (94%) rename src/{ => settings}/components/setting.js (95%) rename src/{pages/settings.html => settings/index.html} (100%) rename src/{pages/settings.js => settings/index.js} (67%) rename src/{ => settings}/reducers/setting.js (87%) rename src/{pages/settings.scss => settings/site.scss} (100%) delete mode 100644 test/reducers/setting.test.js diff --git a/src/background/index.js b/src/background/index.js index 63d13cb..c51754b 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -1,4 +1,4 @@ -import * as settingsActions from 'actions/setting'; +import * as settingsActions from 'settings/actions/setting'; import messages from 'shared/messages'; import BackgroundComponent from 'components/background'; import reducers from 'reducers'; diff --git a/src/components/background.js b/src/components/background.js index afb90c2..200fedf 100644 --- a/src/components/background.js +++ b/src/components/background.js @@ -1,6 +1,6 @@ import messages from 'shared/messages'; import * as operationActions from 'actions/operation'; -import * as settingsActions from 'actions/setting'; +import * as settingsActions from 'settings/actions/setting'; import * as tabActions from 'actions/tab'; import * as commands from 'shared/commands'; diff --git a/src/content/index.js b/src/content/index.js index 25a2e74..edca510 100644 --- a/src/content/index.js +++ b/src/content/index.js @@ -1,6 +1,6 @@ import './console-frame.scss'; import * as consoleFrames from './console-frames'; -import * as settingActions from 'actions/setting'; +import * as settingActions from 'settings/actions/setting'; import { createStore } from 'store'; import ContentInputComponent from 'components/content-input'; import KeymapperComponent from 'components/keymapper'; diff --git a/src/reducers/index.js b/src/reducers/index.js index 3ebe491..9c86ebf 100644 --- a/src/reducers/index.js +++ b/src/reducers/index.js @@ -1,7 +1,8 @@ import inputReducer from 'reducers/input'; -import settingReducer from 'reducers/setting'; +import settingReducer from 'settings/reducers/setting'; import followReducer from 'reducers/follow'; +// Make setting reducer instead of re-use const defaultState = { input: inputReducer(undefined, {}), setting: settingReducer(undefined, {}), diff --git a/src/settings/actions/index.js b/src/settings/actions/index.js new file mode 100644 index 0000000..8c212c2 --- /dev/null +++ b/src/settings/actions/index.js @@ -0,0 +1,4 @@ +export default { + // Settings + SETTING_SET_SETTINGS: 'setting.set.settings', +}; diff --git a/src/actions/setting.js b/src/settings/actions/setting.js similarity index 94% rename from src/actions/setting.js rename to src/settings/actions/setting.js index c241428..697bcf0 100644 --- a/src/actions/setting.js +++ b/src/settings/actions/setting.js @@ -1,4 +1,4 @@ -import actions from 'actions'; +import actions from 'settings/actions'; import messages from 'shared/messages'; import DefaultSettings from 'shared/default-settings'; diff --git a/src/components/setting.js b/src/settings/components/setting.js similarity index 95% rename from src/components/setting.js rename to src/settings/components/setting.js index c2f99b6..14482a3 100644 --- a/src/components/setting.js +++ b/src/settings/components/setting.js @@ -1,4 +1,4 @@ -import * as settingActions from 'actions/setting'; +import * as settingActions from 'settings/actions/setting'; import { validate } from 'shared/validators/setting'; export default class SettingComponent { diff --git a/src/pages/settings.html b/src/settings/index.html similarity index 100% rename from src/pages/settings.html rename to src/settings/index.html diff --git a/src/pages/settings.js b/src/settings/index.js similarity index 67% rename from src/pages/settings.js rename to src/settings/index.js index 6e25e6f..8c60f80 100644 --- a/src/pages/settings.js +++ b/src/settings/index.js @@ -1,6 +1,6 @@ -import './settings.scss'; -import SettingComponent from 'components/setting'; -import settingReducer from 'reducers/setting'; +import './site.scss'; +import SettingComponent from 'settings/components/setting'; +import settingReducer from 'settings/reducers/setting'; import { createStore } from 'store'; const store = createStore(settingReducer); diff --git a/src/reducers/setting.js b/src/settings/reducers/setting.js similarity index 87% rename from src/reducers/setting.js rename to src/settings/reducers/setting.js index 7326ed7..f7d9242 100644 --- a/src/reducers/setting.js +++ b/src/settings/reducers/setting.js @@ -1,4 +1,4 @@ -import actions from 'actions'; +import actions from 'settings/actions'; const defaultState = { settings: {} diff --git a/src/pages/settings.scss b/src/settings/site.scss similarity index 100% rename from src/pages/settings.scss rename to src/settings/site.scss diff --git a/test/reducers/setting.test.js b/test/reducers/setting.test.js deleted file mode 100644 index 1af031a..0000000 --- a/test/reducers/setting.test.js +++ /dev/null @@ -1,22 +0,0 @@ -import { expect } from "chai"; -import actions from 'actions'; -import settingReducer from 'reducers/setting'; - -describe("setting reducer", () => { - it('return the initial state', () => { - let state = settingReducer(undefined, {}); - expect(state).to.have.deep.property('settings', {}); - }); - - it('return next state for SETTING_SET_SETTINGS', () => { - let action = { - type: actions.SETTING_SET_SETTINGS, - settings: { value1: 'hello', value2: 'world' }, - }; - let state = settingReducer(undefined, action); - expect(state).to.have.deep.property('settings', { - value1: 'hello', - value2: 'world', - }); - }); -}); diff --git a/webpack.config.js b/webpack.config.js index 486814a..bc3bb1c 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -7,7 +7,7 @@ const dist = path.resolve(__dirname, 'build'); module.exports = { entry: { index: path.join(src, 'content'), - settings: path.join(src, 'pages/settings'), + settings: path.join(src, 'settings'), background: path.join(src, 'background'), console: path.join(src, 'console') }, @@ -50,7 +50,7 @@ module.exports = { inject: false }), new HtmlWebpackPlugin({ - template: path.join(src, 'pages', 'settings.html'), + template: path.join(src, 'settings', 'index.html'), filename: path.join(dist, 'settings.html'), inject: false }) From d886d7de290b6fee00c55c5487416048f3de4bf2 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 8 Oct 2017 14:57:27 +0900 Subject: [PATCH 4/7] move background --- src/actions/operation.js | 50 +----------------- src/background/actions/index.js | 0 src/background/actions/operation.js | 52 +++++++++++++++++++ src/{ => background}/actions/tab.js | 0 src/{ => background}/components/background.js | 10 ++-- src/background/index.js | 4 +- test/settings/reducers/setting.test.js | 22 ++++++++ 7 files changed, 82 insertions(+), 56 deletions(-) create mode 100644 src/background/actions/index.js create mode 100644 src/background/actions/operation.js rename src/{ => background}/actions/tab.js (100%) rename src/{ => background}/components/background.js (88%) create mode 100644 test/settings/reducers/setting.test.js diff --git a/src/actions/operation.js b/src/actions/operation.js index 8b1590b..a27cd02 100644 --- a/src/actions/operation.js +++ b/src/actions/operation.js @@ -1,18 +1,9 @@ import operations from 'shared/operations'; import messages from 'shared/messages'; -import * as tabs from 'background/tabs'; -import * as zooms from 'background/zooms'; import * as scrolls from 'content/scrolls'; import * as navigates from 'content/navigates'; import * as followActions from 'actions/follow'; -const sendConsoleShowCommand = (tab, command) => { - return browser.tabs.sendMessage(tab.id, { - type: messages.CONSOLE_SHOW_COMMAND, - command, - }); -}; - const exec = (operation) => { switch (operation.type) { case operations.SCROLL_LINES: @@ -49,43 +40,4 @@ const exec = (operation) => { } }; -const execBackground = (operation, tab) => { - switch (operation.type) { - case operations.TAB_CLOSE: - return tabs.closeTab(tab.id); - case operations.TAB_REOPEN: - return tabs.reopenTab(); - case operations.TAB_PREV: - return tabs.selectPrevTab(tab.index, operation.count); - case operations.TAB_NEXT: - return tabs.selectNextTab(tab.index, operation.count); - case operations.TAB_RELOAD: - return tabs.reload(tab, operation.cache); - case operations.ZOOM_IN: - return zooms.zoomIn(); - case operations.ZOOM_OUT: - return zooms.zoomOut(); - case operations.ZOOM_NEUTRAL: - return zooms.neutral(); - case operations.COMMAND_SHOW: - return sendConsoleShowCommand(tab, ''); - case operations.COMMAND_SHOW_OPEN: - if (operation.alter) { - // alter url - return sendConsoleShowCommand(tab, 'open ' + tab.url); - } - return sendConsoleShowCommand(tab, 'open '); - case operations.COMMAND_SHOW_TABOPEN: - if (operation.alter) { - // alter url - return sendConsoleShowCommand(tab, 'tabopen ' + tab.url); - } - return sendConsoleShowCommand(tab, 'tabopen '); - case operations.COMMAND_SHOW_BUFFER: - return sendConsoleShowCommand(tab, 'buffer '); - default: - return Promise.resolve(); - } -}; - -export { exec, execBackground }; +export { exec }; diff --git a/src/background/actions/index.js b/src/background/actions/index.js new file mode 100644 index 0000000..e69de29 diff --git a/src/background/actions/operation.js b/src/background/actions/operation.js new file mode 100644 index 0000000..d736c09 --- /dev/null +++ b/src/background/actions/operation.js @@ -0,0 +1,52 @@ +import operations from 'shared/operations'; +import messages from 'shared/messages'; +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: + return tabs.closeTab(tab.id); + case operations.TAB_REOPEN: + return tabs.reopenTab(); + case operations.TAB_PREV: + return tabs.selectPrevTab(tab.index, operation.count); + case operations.TAB_NEXT: + return tabs.selectNextTab(tab.index, operation.count); + case operations.TAB_RELOAD: + return tabs.reload(tab, operation.cache); + case operations.ZOOM_IN: + return zooms.zoomIn(); + case operations.ZOOM_OUT: + return zooms.zoomOut(); + case operations.ZOOM_NEUTRAL: + return zooms.neutral(); + case operations.COMMAND_SHOW: + return sendConsoleShowCommand(tab, ''); + case operations.COMMAND_SHOW_OPEN: + if (operation.alter) { + // alter url + return sendConsoleShowCommand(tab, 'open ' + tab.url); + } + return sendConsoleShowCommand(tab, 'open '); + case operations.COMMAND_SHOW_TABOPEN: + if (operation.alter) { + // alter url + return sendConsoleShowCommand(tab, 'tabopen ' + tab.url); + } + return sendConsoleShowCommand(tab, 'tabopen '); + case operations.COMMAND_SHOW_BUFFER: + return sendConsoleShowCommand(tab, 'buffer '); + default: + return Promise.resolve(); + } +}; + +export { exec }; diff --git a/src/actions/tab.js b/src/background/actions/tab.js similarity index 100% rename from src/actions/tab.js rename to src/background/actions/tab.js diff --git a/src/components/background.js b/src/background/components/background.js similarity index 88% rename from src/components/background.js rename to src/background/components/background.js index 200fedf..bfe1b3f 100644 --- a/src/components/background.js +++ b/src/background/components/background.js @@ -1,7 +1,7 @@ import messages from 'shared/messages'; -import * as operationActions from 'actions/operation'; +import * as operationActions from 'background/actions/operation'; import * as settingsActions from 'settings/actions/setting'; -import * as tabActions from 'actions/tab'; +import * as tabActions from 'background/actions/tab'; import * as commands from 'shared/commands'; export default class BackgroundComponent { @@ -23,7 +23,7 @@ export default class BackgroundComponent { update() { let state = this.store.getState(); - this.updateSettings(state.setting); + this.updateSettings(state); } updateSettings(setting) { @@ -37,7 +37,7 @@ export default class BackgroundComponent { switch (message.type) { case messages.BACKGROUND_OPERATION: return this.store.dispatch( - operationActions.execBackground(message.operation, sender.tab), + operationActions.exec(message.operation, sender.tab), sender); case messages.OPEN_URL: if (message.newTab) { @@ -58,7 +58,7 @@ export default class BackgroundComponent { }); }); case messages.SETTINGS_QUERY: - return Promise.resolve(this.store.getState().setting.settings); + return Promise.resolve(this.store.getState().settings); case messages.CONSOLE_QUERY_COMPLETIONS: return commands.complete(message.text, this.settings); case messages.SETTINGS_RELOAD: diff --git a/src/background/index.js b/src/background/index.js index c51754b..587cc0b 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -1,7 +1,7 @@ import * as settingsActions from 'settings/actions/setting'; import messages from 'shared/messages'; -import BackgroundComponent from 'components/background'; -import reducers from 'reducers'; +import BackgroundComponent from 'background/components/background'; +import reducers from 'settings/reducers/setting'; import { createStore } from 'store'; const store = createStore(reducers, (e, sender) => { diff --git a/test/settings/reducers/setting.test.js b/test/settings/reducers/setting.test.js new file mode 100644 index 0000000..0e84247 --- /dev/null +++ b/test/settings/reducers/setting.test.js @@ -0,0 +1,22 @@ +import { expect } from "chai"; +import actions from 'settings/actions'; +import settingReducer from 'settings/reducers/setting'; + +describe("setting reducer", () => { + it('return the initial state', () => { + let state = settingReducer(undefined, {}); + expect(state).to.have.deep.property('settings', {}); + }); + + it('return next state for SETTING_SET_SETTINGS', () => { + let action = { + type: actions.SETTING_SET_SETTINGS, + settings: { value1: 'hello', value2: 'world' }, + }; + let state = settingReducer(undefined, action); + expect(state).to.have.deep.property('settings', { + value1: 'hello', + value2: 'world', + }); + }); +}); From 39fb5400370b818760dc7bcfe42e74b2512a840d Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 8 Oct 2017 15:04:55 +0900 Subject: [PATCH 5/7] separate content --- src/{ => content}/actions/follow.js | 2 +- src/{ => content}/actions/index.js | 0 src/{ => content}/actions/input.js | 2 +- src/{ => content}/actions/operation.js | 2 +- src/{ => content}/components/content-input.js | 0 src/{ => content}/components/follow.js | 2 +- src/{ => content}/components/keymapper.js | 4 ++-- src/content/index.js | 8 ++++---- src/{ => content}/reducers/follow.js | 2 +- src/{ => content}/reducers/index.js | 4 ++-- src/{ => content}/reducers/input.js | 2 +- test/{ => content}/actions/follow.test.js | 4 ++-- test/{ => content}/actions/input.test.js | 4 ++-- test/{ => content}/components/follow.html | 0 test/{ => content}/components/follow.test.js | 4 ++-- test/{ => content}/reducers/follow.test.js | 4 ++-- test/{ => content}/reducers/input.test.js | 4 ++-- 17 files changed, 24 insertions(+), 24 deletions(-) rename src/{ => content}/actions/follow.js (91%) rename src/{ => content}/actions/index.js (100%) rename src/{ => content}/actions/input.js (90%) rename src/{ => content}/actions/operation.js (95%) rename src/{ => content}/components/content-input.js (100%) rename src/{ => content}/components/follow.js (98%) rename src/{ => content}/components/keymapper.js (89%) rename src/{ => content}/reducers/follow.js (94%) rename src/{ => content}/reducers/index.js (85%) rename src/{ => content}/reducers/input.js (90%) rename test/{ => content}/actions/follow.test.js (90%) rename test/{ => content}/actions/input.test.js (88%) rename test/{ => content}/components/follow.html (100%) rename test/{ => content}/components/follow.test.js (69%) rename test/{ => content}/reducers/follow.test.js (94%) rename test/{ => content}/reducers/input.test.js (90%) diff --git a/src/actions/follow.js b/src/content/actions/follow.js similarity index 91% rename from src/actions/follow.js rename to src/content/actions/follow.js index 708cd95..5a18dd5 100644 --- a/src/actions/follow.js +++ b/src/content/actions/follow.js @@ -1,4 +1,4 @@ -import actions from 'actions'; +import actions from 'content/actions'; const enable = (newTab) => { return { diff --git a/src/actions/index.js b/src/content/actions/index.js similarity index 100% rename from src/actions/index.js rename to src/content/actions/index.js diff --git a/src/actions/input.js b/src/content/actions/input.js similarity index 90% rename from src/actions/input.js rename to src/content/actions/input.js index 61acb76..cc4efac 100644 --- a/src/actions/input.js +++ b/src/content/actions/input.js @@ -1,4 +1,4 @@ -import actions from 'actions'; +import actions from 'content/actions'; const asKeymapChars = (key, ctrl) => { if (ctrl) { diff --git a/src/actions/operation.js b/src/content/actions/operation.js similarity index 95% rename from src/actions/operation.js rename to src/content/actions/operation.js index a27cd02..d188a60 100644 --- a/src/actions/operation.js +++ b/src/content/actions/operation.js @@ -2,7 +2,7 @@ import operations from 'shared/operations'; import messages from 'shared/messages'; import * as scrolls from 'content/scrolls'; import * as navigates from 'content/navigates'; -import * as followActions from 'actions/follow'; +import * as followActions from 'content/actions/follow'; const exec = (operation) => { switch (operation.type) { diff --git a/src/components/content-input.js b/src/content/components/content-input.js similarity index 100% rename from src/components/content-input.js rename to src/content/components/content-input.js diff --git a/src/components/follow.js b/src/content/components/follow.js similarity index 98% rename from src/components/follow.js rename to src/content/components/follow.js index 0ec1e87..c87424d 100644 --- a/src/components/follow.js +++ b/src/content/components/follow.js @@ -1,4 +1,4 @@ -import * as followActions from 'actions/follow'; +import * as followActions from 'content/actions/follow'; import messages from 'shared/messages'; import Hint from 'content/hint'; import HintKeyProducer from 'content/hint-key-producer'; diff --git a/src/components/keymapper.js b/src/content/components/keymapper.js similarity index 89% rename from src/components/keymapper.js rename to src/content/components/keymapper.js index 3685a4f..8f2cead 100644 --- a/src/components/keymapper.js +++ b/src/content/components/keymapper.js @@ -1,5 +1,5 @@ -import * as inputActions from 'actions/input'; -import * as operationActions from 'actions/operation'; +import * as inputActions from 'content/actions/input'; +import * as operationActions from 'content/actions/operation'; export default class KeymapperComponent { constructor(store) { diff --git a/src/content/index.js b/src/content/index.js index edca510..00873cc 100644 --- a/src/content/index.js +++ b/src/content/index.js @@ -2,10 +2,10 @@ import './console-frame.scss'; import * as consoleFrames from './console-frames'; import * as settingActions from 'settings/actions/setting'; import { createStore } from 'store'; -import ContentInputComponent from 'components/content-input'; -import KeymapperComponent from 'components/keymapper'; -import FollowComponent from 'components/follow'; -import reducers from 'reducers'; +import ContentInputComponent from 'content/components/content-input'; +import KeymapperComponent from 'content/components/keymapper'; +import FollowComponent from 'content/components/follow'; +import reducers from 'content/reducers'; import messages from 'shared/messages'; const store = createStore(reducers); diff --git a/src/reducers/follow.js b/src/content/reducers/follow.js similarity index 94% rename from src/reducers/follow.js rename to src/content/reducers/follow.js index ed875e8..b7c0cf3 100644 --- a/src/reducers/follow.js +++ b/src/content/reducers/follow.js @@ -1,4 +1,4 @@ -import actions from 'actions'; +import actions from 'content/actions'; const defaultState = { enabled: false, diff --git a/src/reducers/index.js b/src/content/reducers/index.js similarity index 85% rename from src/reducers/index.js rename to src/content/reducers/index.js index 9c86ebf..a62217f 100644 --- a/src/reducers/index.js +++ b/src/content/reducers/index.js @@ -1,6 +1,6 @@ -import inputReducer from 'reducers/input'; import settingReducer from 'settings/reducers/setting'; -import followReducer from 'reducers/follow'; +import inputReducer from './input'; +import followReducer from './follow'; // Make setting reducer instead of re-use const defaultState = { diff --git a/src/reducers/input.js b/src/content/reducers/input.js similarity index 90% rename from src/reducers/input.js rename to src/content/reducers/input.js index 2e4bcd8..802020f 100644 --- a/src/reducers/input.js +++ b/src/content/reducers/input.js @@ -1,4 +1,4 @@ -import actions from 'actions'; +import actions from 'content/actions'; const defaultState = { keys: '', diff --git a/test/actions/follow.test.js b/test/content/actions/follow.test.js similarity index 90% rename from test/actions/follow.test.js rename to test/content/actions/follow.test.js index 32ab9e2..3ac844c 100644 --- a/test/actions/follow.test.js +++ b/test/content/actions/follow.test.js @@ -1,6 +1,6 @@ import { expect } from "chai"; -import actions from 'actions'; -import * as followActions from 'actions/follow'; +import actions from 'content/actions'; +import * as followActions from 'content/actions/follow'; describe('follow actions', () => { describe('enable', () => { diff --git a/test/actions/input.test.js b/test/content/actions/input.test.js similarity index 88% rename from test/actions/input.test.js rename to test/content/actions/input.test.js index 0a2ab18..6031829 100644 --- a/test/actions/input.test.js +++ b/test/content/actions/input.test.js @@ -1,6 +1,6 @@ import { expect } from "chai"; -import actions from 'actions'; -import * as inputActions from 'actions/input'; +import actions from 'content/actions'; +import * as inputActions from 'content/actions/input'; describe("input actions", () => { describe("keyPress", () => { diff --git a/test/components/follow.html b/test/content/components/follow.html similarity index 100% rename from test/components/follow.html rename to test/content/components/follow.html diff --git a/test/components/follow.test.js b/test/content/components/follow.test.js similarity index 69% rename from test/components/follow.test.js rename to test/content/components/follow.test.js index 294bfc9..9c00c79 100644 --- a/test/components/follow.test.js +++ b/test/content/components/follow.test.js @@ -1,10 +1,10 @@ import { expect } from "chai"; -import FollowComponent from 'components/follow'; +import FollowComponent from 'content/components/follow'; describe('FollowComponent', () => { describe('#getTargetElements', () => { beforeEach(() => { - document.body.innerHTML = __html__['test/components/follow.html']; + document.body.innerHTML = __html__['test/content/components/follow.html']; }); it('returns visible links', () => { diff --git a/test/reducers/follow.test.js b/test/content/reducers/follow.test.js similarity index 94% rename from test/reducers/follow.test.js rename to test/content/reducers/follow.test.js index e1db680..e2b3445 100644 --- a/test/reducers/follow.test.js +++ b/test/content/reducers/follow.test.js @@ -1,6 +1,6 @@ import { expect } from "chai"; -import actions from 'actions'; -import followReducer from 'reducers/follow'; +import actions from 'content/actions'; +import followReducer from 'content/reducers/follow'; describe('follow reducer', () => { it ('returns the initial state', () => { diff --git a/test/reducers/input.test.js b/test/content/reducers/input.test.js similarity index 90% rename from test/reducers/input.test.js rename to test/content/reducers/input.test.js index 7b5a89c..d5e5f6b 100644 --- a/test/reducers/input.test.js +++ b/test/content/reducers/input.test.js @@ -1,6 +1,6 @@ import { expect } from "chai"; -import actions from 'actions'; -import inputReducer from 'reducers/input'; +import actions from 'content/actions'; +import inputReducer from 'content/reducers/input'; describe("input reducer", () => { it('return the initial state', () => { From 2faf44af7443b3f858e15d63295a490afba83b4e Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 8 Oct 2017 15:11:09 +0900 Subject: [PATCH 6/7] move store to shared --- src/background/index.js | 2 +- src/console/index.js | 2 +- src/content/index.js | 2 +- src/settings/index.js | 2 +- src/{ => shared}/store/index.js | 0 test/{ => shared}/store/index.test.js | 2 +- 6 files changed, 5 insertions(+), 5 deletions(-) rename src/{ => shared}/store/index.js (100%) rename test/{ => shared}/store/index.test.js (98%) diff --git a/src/background/index.js b/src/background/index.js index 587cc0b..6ba37eb 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -2,7 +2,7 @@ import * as settingsActions from 'settings/actions/setting'; import messages from 'shared/messages'; import BackgroundComponent from 'background/components/background'; import reducers from 'settings/reducers/setting'; -import { createStore } from 'store'; +import { createStore } from 'shared/store'; const store = createStore(reducers, (e, sender) => { console.error('Vim-Vixen:', e); diff --git a/src/console/index.js b/src/console/index.js index 1bcf8bc..7396a96 100644 --- a/src/console/index.js +++ b/src/console/index.js @@ -3,7 +3,7 @@ import messages from 'shared/messages'; import CompletionComponent from 'console/components/completion'; import ConsoleComponent from 'console/components/console'; import reducers from 'console/reducers'; -import { createStore } from 'store'; +import { createStore } from 'shared/store'; import * as consoleActions from 'console/actions/console'; const store = createStore(reducers); diff --git a/src/content/index.js b/src/content/index.js index 00873cc..adea871 100644 --- a/src/content/index.js +++ b/src/content/index.js @@ -1,7 +1,7 @@ import './console-frame.scss'; import * as consoleFrames from './console-frames'; import * as settingActions from 'settings/actions/setting'; -import { createStore } from 'store'; +import { createStore } from 'shared/store'; import ContentInputComponent from 'content/components/content-input'; import KeymapperComponent from 'content/components/keymapper'; import FollowComponent from 'content/components/follow'; diff --git a/src/settings/index.js b/src/settings/index.js index 8c60f80..c8d6cc4 100644 --- a/src/settings/index.js +++ b/src/settings/index.js @@ -1,7 +1,7 @@ import './site.scss'; import SettingComponent from 'settings/components/setting'; import settingReducer from 'settings/reducers/setting'; -import { createStore } from 'store'; +import { createStore } from 'shared/store'; const store = createStore(settingReducer); let settingComponent = null; diff --git a/src/store/index.js b/src/shared/store/index.js similarity index 100% rename from src/store/index.js rename to src/shared/store/index.js diff --git a/test/store/index.test.js b/test/shared/store/index.test.js similarity index 98% rename from test/store/index.test.js rename to test/shared/store/index.test.js index 5dce715..133033b 100644 --- a/test/store/index.test.js +++ b/test/shared/store/index.test.js @@ -1,5 +1,5 @@ import { expect } from "chai"; -import { createStore } from 'store'; +import { createStore } from 'shared/store'; describe("Store class", () => { const reducer = (state, action) => { From 57f798044d32ba7f9dc10a34ac31ad5dbdbf56ae Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Sun, 8 Oct 2017 15:15:12 +0900 Subject: [PATCH 7/7] rename background end-point script name --- manifest.json | 2 +- webpack.config.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/manifest.json b/manifest.json index 7c60cdd..216023b 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "content_scripts": [ { "matches": [ "http://*/*", "https://*/*" ], - "js": [ "build/index.js" ] + "js": [ "build/content.js" ] } ], "background": { diff --git a/webpack.config.js b/webpack.config.js index bc3bb1c..fff49d1 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -6,7 +6,7 @@ const dist = path.resolve(__dirname, 'build'); module.exports = { entry: { - index: path.join(src, 'content'), + content: path.join(src, 'content'), settings: path.join(src, 'settings'), background: path.join(src, 'background'), console: path.join(src, 'console')