diff options
| author | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-08-15 20:47:52 +0900 | 
|---|---|---|
| committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-08-15 20:47:52 +0900 | 
| commit | b9fe3343fc46fb9898f6da9cff8bf0e4ab4e982c (patch) | |
| tree | af4dbef491bc25185808234cd1107f2bb05a7ab5 /src/background | |
| parent | ae089cf5f16e5df40e4d14a9fe844ffc83bd6774 (diff) | |
add key-queue test
Diffstat (limited to 'src/background')
| -rw-r--r-- | src/background/index.js | 2 | ||||
| -rw-r--r-- | src/background/key-queue.js | 12 | 
2 files changed, 9 insertions, 5 deletions
diff --git a/src/background/index.js b/src/background/index.js index 604ea92..d27c557 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -2,7 +2,7 @@ import * as actions from '../shared/actions';  import * as tabs from './tabs';  import KeyQueue from './key-queue'; -const queue = new KeyQueue(); +const queue = new KeyQueue(KeyQueue.DEFAULT_KEYMAP);  const keyDownHandle = (request) => {    return queue.push({ diff --git a/src/background/key-queue.js b/src/background/key-queue.js index e21399e..666eec3 100644 --- a/src/background/key-queue.js +++ b/src/background/key-queue.js @@ -12,20 +12,20 @@ const DEFAULT_KEYMAP = [  export default class KeyQueue { -  constructor(keymap) { +  constructor() {      this.data = []; -    this.keymap = keymap; +    this.keymap = DEFAULT_KEYMAP;    }    push(key) {      this.data.push(key); -    let filtered = DEFAULT_KEYMAP.filter((map) => { +    let filtered = this.keymap.filter((map) => {        return keys.hasPrefix(map.keys, this.data)      });      if (filtered.length == 0) {        this.data = []; -      return; +      return null;      } else if (filtered.length == 1) {        let map = filtered[0];        if (map.keys.length == this.data.length) { @@ -35,4 +35,8 @@ export default class KeyQueue {      }      return null;    } + +  queuedKeys() { +    return this.data; +  }  }  | 
