Skip to content

Commit

Permalink
💬 🚀 📚 Abort resetting handler resolution state if it has already been…
Browse files Browse the repository at this point in the history
… reset
  • Loading branch information
greena13 committed May 18, 2019
1 parent eeabff3 commit 7d5b752
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/lib/strategies/AbstractKeyEventStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/lib/strategies/GlobalKeyEventStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ class GlobalKeyEventStrategy extends AbstractKeyEventStrategy {

this._updateDocumentHandlers();

/**
* Reset handler resolution state
*/
this._initHandlerResolutionState();

this.logger.debug(
Expand Down
2 changes: 1 addition & 1 deletion test/GlobalHotKeys/MatchingKeyMapAfterRemount.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down

0 comments on commit 7d5b752

Please sign in to comment.