snippets
- introduction
- copy text with selector
- copy text via a selector with messaging
- copy with quick copy
- debounce a signal
- forward an element as a sender
- get random numbers
- load data from a url
- load templates from a url
- map a key to a signal
- match elements from parent
- measure performance
- poll data
- receive multiple signals
- render an svg
- run an init function
- send and receive from the same element
- send multiple signals at the same time
- send to multiple receivers
- shuffle an array
- style SVGs
- switch
- switch with init
- update the content of an element
- use a template from the page
- use an alternate listener
- use innerHTML as a number
map a key to a signal
The 'a' key has been pressed 0 times.
- Keys can be mapped to signals with
b.mapKey()
html
<div>The 'a' key has been pressed <span data-r="pressed">0</span> times.</div>javascript
export const b = { init: "mapA" };
let count = 0;
export function mapA() {
b.mapKey("a", "pressed");
}
export function pressed(_, __, el) {
count += 1;
el.innerHTML = count;
}