-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix propagation issue where child handlers handling short key sequenc…
…es would prevent parent long key sequences from firing AND Only bother rebinding hotkeys if mappings have changed (on update etc.)
- Loading branch information
Showing
2 changed files
with
74 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,51 @@ | ||
import React from 'react'; | ||
import assign from 'lodash/object/assign'; | ||
import isEqual from 'lodash/lang/isEqual'; | ||
|
||
export default function HotKeyMapMixin(hotKeyMap = {}) { | ||
|
||
return { | ||
|
||
contextTypes: { | ||
hotKeyMap: React.PropTypes.object | ||
}, | ||
|
||
childContextTypes: { | ||
hotKeyMap: React.PropTypes.object | ||
}, | ||
|
||
getChildContext() { | ||
return { | ||
hotKeyMap: this.__hotKeyMap__ | ||
}; | ||
}, | ||
|
||
componentWillMount() { | ||
this.updateMap(); | ||
}, | ||
|
||
updateMap() { | ||
this.__hotKeyMap__ = this.buildMap(); | ||
const newMap = this.buildMap(); | ||
|
||
if (!isEqual(newMap, this.__hotKeyMap__)) { | ||
this.__hotKeyMap__ = newMap; | ||
return true; | ||
} | ||
|
||
return false; | ||
}, | ||
|
||
buildMap() { | ||
const parentMap = this.context.hotKeyMap || {}; | ||
const thisMap = this.props.keyMap || {}; | ||
|
||
return assign({}, parentMap, hotKeyMap, thisMap); | ||
}, | ||
|
||
getMap() { | ||
return this.__hotKeyMap__; | ||
} | ||
|
||
}; | ||
}; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters