Skip to content
Snippets Groups Projects
QuestionWallKeyEventSupport.ts 532 B
Newer Older

export class QuestionWallKeyEventSupport {

  private keyMap: Map<string, () => void> = new Map<string, () => void>();
  private readonly windowEvent;

  constructor() {
    window.addEventListener('keyup', this.windowEvent = e => {
      if (this.keyMap.has(e.key)) {
        this.keyMap.get(e.key)();
Lukas Haase's avatar
Lukas Haase committed
        e.cancelBubble = true;
      }
    });
  }

  public addKeyEvent(key: string, evt: () => void) {
    this.keyMap.set(key, evt);
  }

  public destroy() {
    window.removeEventListener('keyup', this.windowEvent);
  }

}