From 7d5b7528b585423332040d7c70720bcbb6d41b7d Mon Sep 17 00:00:00 2001 From: Aleck Greenham Date: Sat, 18 May 2019 09:15:37 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=AC=20=F0=9F=9A=80=20=F0=9F=93=9A=20Ab?= =?UTF-8?q?ort=20resetting=20handler=20resolution=20state=20if=20it=20has?= =?UTF-8?q?=20already=20been=20reset?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/strategies/AbstractKeyEventStrategy.js | 8 ++++++++ src/lib/strategies/GlobalKeyEventStrategy.js | 3 +++ test/GlobalHotKeys/MatchingKeyMapAfterRemount.spec.js | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/lib/strategies/AbstractKeyEventStrategy.js b/src/lib/strategies/AbstractKeyEventStrategy.js index 8c2a115f..68644c2a 100644 --- a/src/lib/strategies/AbstractKeyEventStrategy.js +++ b/src/lib/strategies/AbstractKeyEventStrategy.js @@ -167,6 +167,14 @@ class AbstractKeyEventStrategy { * @protected */ _initHandlerResolutionState() { + if (this.keyMaps === null) { + /** + * If this.keyMaps is already set to null, then the state has already been reset + * and we need not do it again + */ + return; + } + /** * List of mappings from key sequences to handlers that is constructed on-the-fly * as key events propagate up the render tree diff --git a/src/lib/strategies/GlobalKeyEventStrategy.js b/src/lib/strategies/GlobalKeyEventStrategy.js index 02f0caa2..c39a04b8 100644 --- a/src/lib/strategies/GlobalKeyEventStrategy.js +++ b/src/lib/strategies/GlobalKeyEventStrategy.js @@ -73,6 +73,9 @@ class GlobalKeyEventStrategy extends AbstractKeyEventStrategy { this._updateDocumentHandlers(); + /** + * Reset handler resolution state + */ this._initHandlerResolutionState(); this.logger.debug( diff --git a/test/GlobalHotKeys/MatchingKeyMapAfterRemount.spec.js b/test/GlobalHotKeys/MatchingKeyMapAfterRemount.spec.js index 08af2bf8..a208c238 100644 --- a/test/GlobalHotKeys/MatchingKeyMapAfterRemount.spec.js +++ b/test/GlobalHotKeys/MatchingKeyMapAfterRemount.spec.js @@ -54,7 +54,7 @@ describe('Matching key map after remount for a GlobalHotKeys component:', functi document.body.removeChild(this.reactDiv); }); - describe.only('when two GlobalHotKeys components are mounted, unmounted and remounted', () => { + describe('when two GlobalHotKeys components are mounted, unmounted and remounted', () => { it('then both of their key maps work while they are mounted and not, when they aren\'t (BUG: https://github.com/greena13/react-hotkeys/issues/150)', function() { simulant.fire(this.reactDiv, 'keydown', { key: KeyCode.A }); simulant.fire(this.reactDiv, 'keypress', { key: KeyCode.A });