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
shuffle an array
- The
b.shuffle()method provides a basic shuffling of an array of strings.
html
<div data-r="items"></div>
<button data-s="shuffle">Shuffle</button>javascript
export const b = { init: "items" };
const theItems = ["alfa", "bravo", "charlie", "delta", "echo", "foxtrot"];
export function items(_, __, el) {
el.innerHTML = theItems.join(" - ");
}
export function shuffle(_, __, ___) {
b.shuffle(theItems);
b.trigger("items");
}