Created
December 15, 2016 21:07
-
-
Save casesandberg/2a9367ee3ec51fc2fff4a00fa9ea800e to your computer and use it in GitHub Desktop.
Dispatching Actions With Hotkeys Using Mousetrap
This file contains hidden or 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
import Mousetrap from 'mousetrap' | |
export const init = (dispatch, state) => { | |
const keymaps = getKeymaps() | |
_.each(keymaps, (action, combo) => { | |
Mousetrap.bind(combo, () => { | |
dispatch(action(dispatch, state)) | |
}) | |
}) | |
} |
This file contains hidden or 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
import { actions } from './reducer' | |
export default { | |
// single | |
'command-b': actions.toggleListVisibility, | |
// or multiple | |
'command-n': (dispatch) => { | |
dispatch(actions.toggleListVisibility).then( | |
dispatch(actions.addToList) | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment