Skip to content

Instantly share code, notes, and snippets.

@casesandberg
Created December 15, 2016 21:07
Show Gist options
  • Save casesandberg/2a9367ee3ec51fc2fff4a00fa9ea800e to your computer and use it in GitHub Desktop.
Save casesandberg/2a9367ee3ec51fc2fff4a00fa9ea800e to your computer and use it in GitHub Desktop.
Dispatching Actions With Hotkeys Using Mousetrap
import Mousetrap from 'mousetrap'
export const init = (dispatch, state) => {
const keymaps = getKeymaps()
_.each(keymaps, (action, combo) => {
Mousetrap.bind(combo, () => {
dispatch(action(dispatch, state))
})
})
}
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