Merge pull request #22 from ueokande/separate-domains

Refactor: Separate domains
jh-changes
Shin'ya Ueoka 7 years ago committed by GitHub
commit 0183161145
  1. 2
      manifest.json
  2. 0
      src/background/actions/index.js
  3. 45
      src/background/actions/operation.js
  4. 0
      src/background/actions/tab.js
  5. 14
      src/background/components/background.js
  6. 10
      src/background/index.js
  7. 2
      src/console/actions/console.js
  8. 9
      src/console/actions/index.js
  9. 2
      src/console/components/completion.js
  10. 6
      src/console/components/console.js
  11. 0
      src/console/index.html
  12. 14
      src/console/index.js
  13. 2
      src/console/reducers/index.js
  14. 0
      src/console/site.scss
  15. 2
      src/content/actions/follow.js
  16. 8
      src/content/actions/index.js
  17. 2
      src/content/actions/input.js
  18. 43
      src/content/actions/operation.js
  19. 0
      src/content/components/content-input.js
  20. 4
      src/content/components/follow.js
  21. 4
      src/content/components/keymapper.js
  22. 14
      src/content/index.js
  23. 2
      src/content/reducers/follow.js
  24. 10
      src/content/reducers/index.js
  25. 2
      src/content/reducers/input.js
  26. 4
      src/settings/actions/index.js
  27. 4
      src/settings/actions/setting.js
  28. 2
      src/settings/components/setting.js
  29. 0
      src/settings/index.html
  30. 8
      src/settings/index.js
  31. 2
      src/settings/reducers/setting.js
  32. 0
      src/settings/site.scss
  33. 0
      src/shared/messages.js
  34. 0
      src/shared/store/index.js
  35. 4
      test/console/actions/console.test.js
  36. 30
      test/console/reducers/console.test.js
  37. 4
      test/content/actions/follow.test.js
  38. 4
      test/content/actions/input.test.js
  39. 0
      test/content/components/follow.html
  40. 4
      test/content/components/follow.test.js
  41. 4
      test/content/reducers/follow.test.js
  42. 4
      test/content/reducers/input.test.js
  43. 4
      test/settings/reducers/setting.test.js
  44. 2
      test/shared/store/index.test.js
  45. 10
      webpack.config.js

@ -6,7 +6,7 @@
"content_scripts": [
{
"matches": [ "http://*/*", "https://*/*" ],
"js": [ "build/index.js" ]
"js": [ "build/content.js" ]
}
],
"background": {

@ -1,10 +1,7 @@
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';
import * as navigates from 'content/navigates';
import * as followActions from 'actions/follow';
const sendConsoleShowCommand = (tab, command) => {
return browser.tabs.sendMessage(tab.id, {
@ -13,43 +10,7 @@ const sendConsoleShowCommand = (tab, command) => {
});
};
const exec = (operation) => {
switch (operation.type) {
case operations.SCROLL_LINES:
return scrolls.scrollLines(window, operation.count);
case operations.SCROLL_PAGES:
return scrolls.scrollPages(window, operation.count);
case operations.SCROLL_TOP:
return scrolls.scrollTop(window);
case operations.SCROLL_BOTTOM:
return scrolls.scrollBottom(window);
case operations.SCROLL_HOME:
return scrolls.scrollLeft(window);
case operations.SCROLL_END:
return scrolls.scrollRight(window);
case operations.FOLLOW_START:
return followActions.enable(false);
case operations.NAVIGATE_HISTORY_PREV:
return navigates.historyPrev(window);
case operations.NAVIGATE_HISTORY_NEXT:
return navigates.historyNext(window);
case operations.NAVIGATE_LINK_PREV:
return navigates.linkPrev(window);
case operations.NAVIGATE_LINK_NEXT:
return navigates.linkNext(window);
case operations.NAVIGATE_PARENT:
return navigates.parent(window);
case operations.NAVIGATE_ROOT:
return navigates.root(window);
default:
browser.runtime.sendMessage({
type: messages.BACKGROUND_OPERATION,
operation,
});
}
};
const execBackground = (operation, tab) => {
const exec = (operation, tab) => {
switch (operation.type) {
case operations.TAB_CLOSE:
return tabs.closeTab(tab.id);
@ -88,4 +49,4 @@ const execBackground = (operation, tab) => {
}
};
export { exec, execBackground };
export { exec };

@ -1,7 +1,7 @@
import messages from 'content/messages';
import * as operationActions from 'actions/operation';
import * as settingsActions from 'actions/setting';
import * as tabActions from 'actions/tab';
import messages from 'shared/messages';
import * as operationActions from 'background/actions/operation';
import * as settingsActions from 'settings/actions/setting';
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:

@ -1,8 +1,8 @@
import * as settingsActions from 'actions/setting';
import messages from 'content/messages';
import BackgroundComponent from 'components/background';
import reducers from 'reducers';
import { createStore } from 'store';
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 'shared/store';
const store = createStore(reducers, (e, sender) => {
console.error('Vim-Vixen:', e);

@ -1,4 +1,4 @@
import actions from 'actions';
import actions from 'console/actions';
const showCommand = (text) => {
return {

@ -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',
};

@ -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;
}

@ -1,5 +1,5 @@
import messages from 'content/messages';
import * as consoleActions from 'actions/console';
import messages from 'shared/messages';
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) {

@ -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 consoleActions from 'actions/console';
import './site.scss';
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 'shared/store';
import * as consoleActions from 'console/actions/console';
const store = createStore(reducers);
let completionComponent = null;

@ -1,4 +1,4 @@
import actions from 'actions';
import actions from 'console/actions';
const defaultState = {
errorShown: false,

@ -1,4 +1,4 @@
import actions from 'actions';
import actions from 'content/actions';
const enable = (newTab) => {
return {

@ -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',

@ -1,4 +1,4 @@
import actions from 'actions';
import actions from 'content/actions';
const asKeymapChars = (key, ctrl) => {
if (ctrl) {

@ -0,0 +1,43 @@
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 'content/actions/follow';
const exec = (operation) => {
switch (operation.type) {
case operations.SCROLL_LINES:
return scrolls.scrollLines(window, operation.count);
case operations.SCROLL_PAGES:
return scrolls.scrollPages(window, operation.count);
case operations.SCROLL_TOP:
return scrolls.scrollTop(window);
case operations.SCROLL_BOTTOM:
return scrolls.scrollBottom(window);
case operations.SCROLL_HOME:
return scrolls.scrollLeft(window);
case operations.SCROLL_END:
return scrolls.scrollRight(window);
case operations.FOLLOW_START:
return followActions.enable(false);
case operations.NAVIGATE_HISTORY_PREV:
return navigates.historyPrev(window);
case operations.NAVIGATE_HISTORY_NEXT:
return navigates.historyNext(window);
case operations.NAVIGATE_LINK_PREV:
return navigates.linkPrev(window);
case operations.NAVIGATE_LINK_NEXT:
return navigates.linkNext(window);
case operations.NAVIGATE_PARENT:
return navigates.parent(window);
case operations.NAVIGATE_ROOT:
return navigates.root(window);
default:
browser.runtime.sendMessage({
type: messages.BACKGROUND_OPERATION,
operation,
});
}
};
export { exec };

@ -1,5 +1,5 @@
import * as followActions from 'actions/follow';
import messages from 'content/messages';
import * as followActions from 'content/actions/follow';
import messages from 'shared/messages';
import Hint from 'content/hint';
import HintKeyProducer from 'content/hint-key-producer';

@ -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) {

@ -1,12 +1,12 @@
import './console-frame.scss';
import * as consoleFrames from './console-frames';
import * as settingActions from '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 messages from './messages';
import * as settingActions from 'settings/actions/setting';
import { createStore } from 'shared/store';
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);
const followComponent = new FollowComponent(window.document.body, store);

@ -1,4 +1,4 @@
import actions from 'actions';
import actions from 'content/actions';
const defaultState = {
enabled: false,

@ -1,11 +1,10 @@
import inputReducer from 'reducers/input';
import consoleReducer from 'reducers/console';
import settingReducer from 'reducers/setting';
import followReducer from 'reducers/follow';
import settingReducer from 'settings/reducers/setting';
import inputReducer from './input';
import followReducer from './follow';
// Make setting reducer instead of re-use
const defaultState = {
input: inputReducer(undefined, {}),
console: consoleReducer(undefined, {}),
setting: settingReducer(undefined, {}),
follow: followReducer(undefined, {}),
};
@ -13,7 +12,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),
});

@ -1,4 +1,4 @@
import actions from 'actions';
import actions from 'content/actions';
const defaultState = {
keys: '',

@ -0,0 +1,4 @@
export default {
// Settings
SETTING_SET_SETTINGS: 'setting.set.settings',
};

@ -1,5 +1,5 @@
import actions from 'actions';
import messages from 'content/messages';
import actions from 'settings/actions';
import messages from 'shared/messages';
import DefaultSettings from 'shared/default-settings';
const load = () => {

@ -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 {

@ -1,7 +1,7 @@
import './settings.scss';
import SettingComponent from 'components/setting';
import settingReducer from 'reducers/setting';
import { createStore } from 'store';
import './site.scss';
import SettingComponent from 'settings/components/setting';
import settingReducer from 'settings/reducers/setting';
import { createStore } from 'shared/store';
const store = createStore(settingReducer);
let settingComponent = null;

@ -1,4 +1,4 @@
import actions from 'actions';
import actions from 'settings/actions';
const defaultState = {
settings: {}

@ -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", () => {

@ -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);
});

@ -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', () => {

@ -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", () => {

@ -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', () => {

@ -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', () => {

@ -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', () => {

@ -1,6 +1,6 @@
import { expect } from "chai";
import actions from 'actions';
import settingReducer from 'reducers/setting';
import actions from 'settings/actions';
import settingReducer from 'settings/reducers/setting';
describe("setting reducer", () => {
it('return the initial state', () => {

@ -1,5 +1,5 @@
import { expect } from "chai";
import { createStore } from 'store';
import { createStore } from 'shared/store';
describe("Store class", () => {
const reducer = (state, action) => {

@ -6,10 +6,10 @@ const dist = path.resolve(__dirname, 'build');
module.exports = {
entry: {
index: path.join(src, 'content'),
settings: path.join(src, 'pages/settings'),
content: path.join(src, 'content'),
settings: path.join(src, 'settings'),
background: path.join(src, 'background'),
console: path.join(src, 'pages', 'console.js')
console: path.join(src, 'console')
},
output: {
@ -45,12 +45,12 @@ 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
}),
new HtmlWebpackPlugin({
template: path.join(src, 'pages', 'settings.html'),
template: path.join(src, 'settings', 'index.html'),
filename: path.join(dist, 'settings.html'),
inject: false
})