Public
Edited
Mar 23, 2024
1 fork
Importers
24 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
mutable nameOfThing = undefined
Insert cell
viewof newName = Inputs.text({
label: "please enter the name of the thing to create",
submit: true,
minlength: 1
})
Insert cell
sideEffect = {
yield md`<mark>updating`;
await new Promise(r => setTimeout(r, 1000));
mutable nameOfThing = newName;

yield md`<mark>updated!!!`;
}
Insert cell
Insert cell
function viewroutine(generator) {
let current;
const holder = Object.defineProperty(
document.createElement("span"),
"value",
{
get: () => current?.value,
set: (v) => (current ? (current.value = v) : null),
enumerable: true
}
);

new Promise(async () => {
const iterator = generator();
const n = await iterator.next();
let { done, value } = n;
while (!done) {
if (value instanceof Event) {
holder.dispatchEvent(value);
} else {
current = value;
if (holder.firstChild) holder.removeChild(holder.firstChild);
if (value) {
holder.appendChild(value);
}
}
({ done, value } = await iterator.next());
}
holder.remove();
});
return holder;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof example1 = viewroutine(async function*() {
let newName = undefined;
while (true) {
newName = yield* ask(
Inputs.text({
label: "please enter the name of the thing to create",
minlength: 1,
value: newName,
submit: true
})
);
yield md`<mark>updating to ${newName}`; // Note we can remember newName
await new Promise(r => setTimeout(r, 1000)); // Mock async action
yield* ask(htl.html`${md`<mark>updated`} ${Inputs.button("Again?")}`);
}
})
Insert cell
example1
Insert cell
Insert cell
choice
Insert cell
viewof choice = viewroutine(async function*() {
while (true) {
const choice = yield* choose();
if (choice == 'square') yield* flashSquare();
if (choice == 'star') yield* flashStar();
}
})
Insert cell
Insert cell
Insert cell
Insert cell
import { footer } from "@tomlarkworthy/footer"
Insert cell
footer
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