aboutsummaryrefslogtreecommitdiff
path: root/src/content/components/common/index.js
diff options
context:
space:
mode:
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));
+ });
+ }
+}