aboutsummaryrefslogblamecommitdiff
path: root/src/content/components/common/index.js
blob: 5f5531b1b9c0e4e2b2f38ff2fd59727d9cc94247 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12

                                             
                                                          






                                                               
                                           







                          
                                                  




                                           
                      
                           







                                    
                                                        

       
import InputComponent from './input';
import KeymapperComponent from './keymapper';
import FollowComponent from './follow';
import * as settingActions from 'content/actions/setting';
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 => follow.key(key));
    input.onKey(key => keymapper.key(key));

    this.store = store;
    this.children = [
      follow,
      input,
      keymapper,
    ];

    this.reloadSettings();

    messages.onMessage(this.onMessage.bind(this));
  }

  update() {
    this.children.forEach(c => c.update());
  }

  onMessage(message) {
    switch (message.type) {
    case messages.SETTINGS_CHANGED:
      this.reloadSettings();
    }
  }

  reloadSettings() {
    browser.runtime.sendMessage({
      type: messages.SETTINGS_QUERY,
    }).then((settings) => {
      this.store.dispatch(settingActions.set(settings));
    });
  }
}