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
style SVGs
- Styles can be applied to SVGs
using
b.render()and substituting class names into the template.
html
<div data-r="loadSVG"></div>
<script type="image/svg" data-template="snippetSVG">
<svg version="1.1" width="200" height="100" xmlns="http://www.w3.org/2000/svg">
<circle class="__COLOR__" cx="100" cy="50" r="50" />
</svg>
</script>javascript
export const b = { init: "loadSVG" };
const colors = ["red", "green", "blue"];
export function loadSVG(_, __, el) {
el.replaceChildren(
...colors.map((color) => {
const subs = { __COLOR__: color };
return b.render("snippetSVG", subs);
}),
);
}styles
.red { fill: red; }
.green { fill: green; }
.blue { fill: blue; }