aboutsummaryrefslogtreecommitdiff
path: root/src/content/components/common/index.js
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-10-15 09:02:09 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2017-10-15 09:04:00 +0900
commit4c9d0433a6ac851e72d50d6fb0451baa9d35fd35 (patch)
tree5b831137fe327e94fd73339e2b395bfe3e98961c /src/content/components/common/index.js
parent042aa94936c9114f0a0fd05fb0a91df8f5565ecd (diff)
make top-content component and frame-content component
Diffstat (limited to 'src/content/components/common/index.js')
-rw-r--r--src/content/components/common/index.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/content/components/common/index.js b/src/content/components/common/index.js
new file mode 100644
index 0000000..7673134
--- /dev/null
+++ b/src/content/components/common/index.js
@@ -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));
+ });
+ }
+}