add key-queue test

This commit is contained in:
Shin'ya Ueoka 2017-08-15 20:47:52 +09:00
parent ae089cf5f1
commit b9fe3343fc
3 changed files with 56 additions and 5 deletions

View file

@ -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({

View file

@ -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;
}
}