Published
Edited
Sep 9, 2020
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
yield 42
Insert cell
Insert cell
42
Insert cell
Insert cell
{
let i = 0;
while (true) {
yield Promises.delay(1000, ++i);
}
}
Insert cell
Insert cell
{
let i = 0;
while (true) {
await Promises.delay(1000);
yield ++i;
}
}
Insert cell
Insert cell
tick = {
while (true) {
yield Promises.delay(1000);
}
}
Insert cell
(tick, md` Este número se atualiza uma vez por segundo: \`${Math.random()}\``)
Insert cell
Insert cell
{
const div = html`<div style="transition:background 250ms linear;height:33px;">`;
yield div;
while (true) {
div.style.background = "red";
yield Promises.delay(1000, div);
div.style.background = "green";
yield Promises.delay(1000, div);
div.style.background = "blue";
yield Promises.delay(1000, div);
}
}
Insert cell
Insert cell
minutes = {
let i;
yield (i = 0);
while (true) yield Promises.delay(60000, ++i);
}
Insert cell
minutes // Shift-Enter or hit play to rerun this cell.
Insert cell
Insert cell
{
let i = 0;
while (true) {
yield ++i;
}
}
Insert cell
Insert cell
{
yield 1;
yield 2;
yield 3;
return "ignored"; // It’s ignored!
}
Insert cell
Insert cell
yield* [1, 2, 3]
Insert cell
yield* new Set([1, 2, 3])
Insert cell
Insert cell
{
while (true) {
yield* range(0, 100);
}
}
Insert cell
Insert cell
input = html`<input type=range>`
Insert cell
Generators.observe(next => {
// Gera (Yield) o valor de entrada inicial
next(input.value);

// Define um event listener para gerar (yield) o valor de entrada do próximo valor.
const inputted = () => next(input.value);

// Anexa o event listener.
input.addEventListener("input", inputted);

// Quando o generator é descartado, desliga o event listener.
return () => input.removeEventListener("input", inputted);
})
Insert cell
Insert cell
Generators.input(input)
Insert cell
Insert cell
viewof value = html`<input type=range>`
Insert cell
value
Insert cell
Insert cell
{
try {
for (let i = 0; i < 100; ++i) {
yield i;
}
} finally {
console.log("terminated!");
}
}
Insert cell
Insert cell
function* range(start, stop) {
start = Math.floor(start);
stop = Math.ceil(stop);
while (start < stop) yield start++;
}
Insert cell
Insert cell
range(0, 100)
Insert cell
Insert cell
width
Insert cell
Insert cell
now
Insert cell
Insert cell
Math.sin(now / 1000)
Insert cell
Insert cell
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