Published
Edited
Feb 4, 2021
2 forks
Importers
33 stars
Insert cell
Insert cell
viewof x = html`<input type=range>`
Insert cell
x
Insert cell
Insert cell
{
viewof x.value = Math.random() * 100;
viewof x.dispatchEvent(new CustomEvent("input"));
}
Insert cell
Insert cell
{
for (let i = 1; i <= 50; ++i) {
viewof x.value = i;
viewof x.dispatchEvent(new CustomEvent("input"));
yield;
}
}
Insert cell
x // The same x as above (and below)!
Insert cell
Insert cell
{
const form = html`<form onsubmit="return false;">
<button name=inc>increment</button>
<button name=dec>decrement</button>
</form>`;
form.inc.onclick = () => {
++viewof x.value;
viewof x.dispatchEvent(new CustomEvent("input"));
};
form.dec.onclick = () => {
--viewof x.value;
viewof x.dispatchEvent(new CustomEvent("input"));
};
return form;
}
Insert cell
Insert cell
{
const input = html`<input type=range min=0 max=100 step=1>`;
input.oninput = () => {
viewof x.value = input.valueAsNumber;
viewof x.dispatchEvent(new CustomEvent("input"));
};
const update = () => input.value = viewof x.value;
viewof x.addEventListener("input", update);
invalidation.then(() => viewof x.removeEventListener("input", update));
return update(), input;
}
Insert cell
x // The same x as above (and below)!
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more