Om is a thin React wrapper for Clojure.
Let’s design a keymap component today.
A keymap component allows us to add some useful key binding as shortcut.
At first, we need a global core.async channel to dispatch events.
UsuallyU we define some keymap groups like
ctrl+b ctrl+v, we actually need a core.async sliding-buffer.
This channel do listen all js.document keydown events, and then put them into self.
We then define an Om component:
For now, it do nothing but insert a
<span></span> tag into html.
The component mounts to the span dom before rendering.
Next, we will add a go-loop to this component.
It will waiting
key-chan inputs and try to compose a meaningful keymap if we pre-defined.
Here we simply print event key into console.
we create a channel waiting keys
Before running it, add some helper functions: