make top-content component and frame-content component

This commit is contained in:
Shin'ya Ueoka 2017-10-15 09:02:09 +09:00
parent 042aa94936
commit 4c9d0433a6
13 changed files with 102 additions and 76 deletions

View file

@ -0,0 +1,46 @@
import InputComponent from './input';
import KeymapperComponent from './keymapper';
import FollowComponent from './follow';
import * as inputActions from 'content/actions/input';
import messages from 'shared/messages';
export default class Common {
constructor(win, store) {
const follow = new FollowComponent(win, store);
const input = new InputComponent(win.document.body, store);
const keymapper = new KeymapperComponent(store);
input.onKey((key, ctrl) => {
follow.key(key, ctrl);
keymapper.key(key, ctrl);
});
this.store = store;
this.children = [
follow,
input,
keymapper,
];
this.reloadSettings();
}
update() {
this.children.forEach(c => c.update());
}
onMessage(message) {
switch (message) {
case messages.SETTINGS_CHANGED:
this.reloadSettings();
}
}
reloadSettings() {
browser.runtime.sendMessage({
type: messages.SETTINGS_QUERY,
}).then((settings) => {
this.store.dispatch(inputActions.setKeymaps(settings.keymaps));
});
}
}

View file

@ -1,4 +1,4 @@
export default class ContentInputComponent {
export default class InputComponent {
constructor(target) {
this.pressed = {};
this.onKeyListeners = [];

View file

@ -0,0 +1,16 @@
import CommonComponent from './common';
export default class FrameContent {
constructor(win, store) {
this.children = [new CommonComponent(win, store)];
}
update() {
this.children.forEach(c => c.update());
}
onMessage(message) {
this.children.forEach(c => c.onMessage(message));
}
}

View file

@ -0,0 +1,28 @@
import CommonComponent from './common';
import * as consoleFrames from '../console-frames';
import messages from 'shared/messages';
export default class TopContent {
constructor(win, store) {
this.win = win;
this.children = [new CommonComponent(win, store)];
// TODO make component
consoleFrames.initialize(window.document);
}
update() {
this.children.forEach(c => c.update());
}
onMessage(message) {
switch (message.type) {
case messages.CONSOLE_HIDE_COMMAND:
this.win.focus();
consoleFrames.blur(window.document);
return Promise.resolve();
}
this.children.forEach(c => c.onMessage(message));
}
}