From 9b8cb032a618d1b0bce089d6acfd06147b429c54 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Mon, 1 Oct 2018 12:50:21 -0700 Subject: [PATCH] Revert "Make hotkeys a function not a singleton class that has side effects when you construct it" This reverts commit 87ca43ba4507cf6a555989570fd0e6ce347c6239. --- js/hotkeys.ts | 12 +++--------- js/webampLazy.js | 5 ++--- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/js/hotkeys.ts b/js/hotkeys.ts index eef797c4..9b57251c 100644 --- a/js/hotkeys.ts +++ b/js/hotkeys.ts @@ -21,7 +21,7 @@ import { TOGGLE_TIME_MODE, TOGGLE_LLAMA_MODE } from "./actionTypes"; import { arraysAreEqual } from "./utils"; import { Dispatch } from "./types"; -export function bindHotkeys(dispatch: Dispatch): () => void { +export default function(dispatch: Dispatch) { let keylog: number[] = []; const trigger = [ 78, // N @@ -33,8 +33,7 @@ export function bindHotkeys(dispatch: Dispatch): () => void { 70, // F 84 // T ]; - - const listener = (e: KeyboardEvent) => { + document.addEventListener("keydown", e => { if (e.ctrlKey) { switch (e.keyCode) { case 68: // CTRL+D @@ -143,10 +142,5 @@ export function bindHotkeys(dispatch: Dispatch): () => void { dispatch({ type: TOGGLE_LLAMA_MODE }); } } - }; - document.addEventListener("keydown", listener); - - return () => { - document.removeEventListener("keydown", listener); - }; + }); } diff --git a/js/webampLazy.js b/js/webampLazy.js index c7db55a4..93e24673 100644 --- a/js/webampLazy.js +++ b/js/webampLazy.js @@ -4,7 +4,7 @@ import { Provider } from "react-redux"; import getStore from "./store"; import App from "./components/App"; -import { bindHotkeys } from "./hotkeys"; +import Hotkeys from "./hotkeys"; import Media from "./media"; import * as Selectors from "./selectors"; import { @@ -65,7 +65,6 @@ class Winamp { } constructor(options) { - this._subscriptions = []; this._actionEmitter = new Emitter(); this.options = options; const { @@ -162,7 +161,7 @@ class Winamp { } if (enableHotkeys) { - this._subscriptions.push(bindHotkeys(this.store.dispatch)); + new Hotkeys(this.store.dispatch); } }