From d9dc12477c685cdc04c9d644357f1c86335fc50b Mon Sep 17 00:00:00 2001 From: jberg Date: Tue, 15 May 2018 19:00:31 -0700 Subject: [PATCH] bind and remove input function --- js/components/MilkdropWindow/index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/js/components/MilkdropWindow/index.js b/js/components/MilkdropWindow/index.js index 899086b6..7a648ac9 100644 --- a/js/components/MilkdropWindow/index.js +++ b/js/components/MilkdropWindow/index.js @@ -44,6 +44,8 @@ class MilkdropWindow extends React.Component { "butterchurn" ); + this._handleKeyboardInput = this._handleKeyboardInput.bind(this); + require.ensure( ["butterchurn-presets"], require => { @@ -54,9 +56,7 @@ class MilkdropWindow extends React.Component { this.cycleInterval = setInterval(() => { this._nextPreset(PRESET_TRANSITION_SECONDS); }, MILLISECONDS_BETWEEN_PRESET_TRANSITIONS); - document.addEventListener("keydown", e => { - this._handleKeyboardInput(e); - }); + document.addEventListener("keydown", this._handleKeyboardInput); }, e => { console.error("Error loading Butterchurn presets", e); @@ -67,6 +67,7 @@ class MilkdropWindow extends React.Component { componentWillUnmount() { this._pauseViz(); this._stopCycling(); + document.removeEventListener("keydown", this._handleKeyboardInput); } componentDidUpdate(prevProps) { if (