synthing

a waveform sequencing synth on the web
Log | Files | Refs | Submodules

commit 5dabe2358a4923b6f41582b67459989b88a3177f
parent 5cc42dbc90968170c98065e5424ce1488480691e
Author: Massimo Siboldi <mdsiboldi@gmail.com>
Date:   Sat, 17 Mar 2018 14:05:08 -0700

Add keybindings component

Diffstat:
Asrc/Keybindings/index.js | 25+++++++++++++++++++++++++
1 file changed, 25 insertions(+), 0 deletions(-)

diff --git a/src/Keybindings/index.js b/src/Keybindings/index.js @@ -0,0 +1,25 @@ +import { h } from 'preact'; +import keymage from 'keymage'; +import { store } from '../store.js'; + +const keybindings = { + 'shift-/': () => {store.dispatch({type: 'TOGGLE_HELP_OPEN'})}, + 'space': { + 'a': () => {console.log('a pressed after space')} + } +} + +const getPrefix = (key, prefix) => prefix ? `${prefix} ${key}` : key; +const registerAll = (keys, prefix) => { + for (let key of Object.keys(keys)) { + if (typeof(keys[key]) === "function") { + keymage(getPrefix(key, prefix), keys[key]); + } + else if (typeof(keys[key]) === "object") { + registerAll(keys[key], getPrefix(key, prefix)); + } + } +} +registerAll(keybindings); + +export default () => (<div>{keybindings}</div>)