Published
Edited
Sep 24, 2019
1 fork
76 stars
Insert cell
Insert cell
{
let i = 0;
yield i;
while (true) {
yield Promises.delay(1000, ++i);
}
}
Insert cell
Insert cell
{
let i = 0;
yield i;
let interval = setInterval(() => {
i++;
}, 1000);
try {
while (true) {
yield i;
}
} finally {
clearInterval(interval); // but dispose if re-evaluated.
}
}
Insert cell
Insert cell
Generators.observe(notify => {
let i = 0;
notify(i);
let interval = setInterval(() => notify(++i), 1000);
return () => clearInterval(interval);
})
Insert cell
Insert cell
// Run this cell
a = [1, 2, 3, 4]
Insert cell
// Then run this cell a few times
a.splice(0, 1)
Insert cell
// Then run this one
a.length
Insert cell
Insert cell
b = [1, 2, 3, 4]
Insert cell
c = {
let copy = b.slice();
copy.splice(0, 1);
return copy;
}
Insert cell
c.length
Insert cell
Insert cell
Insert cell
myObject = ({hi:'Tom'})
Insert cell
myObject.key = Date.now()
Insert cell
myObject
Insert cell
Insert cell
myObjectWithKey = ({ key: Date.now(), ...myObject })
Insert cell
Insert cell
Insert cell
Insert cell
myObjectWithoutHi = _.omit(myObjectWithKey, 'hi')
Insert cell
Insert cell
Insert cell
{
let i = 0;
for (; i < 10; i++) {
yield i;
}
return i;
}
Insert cell
Insert cell
{
let i = 0;
for (; i < 10; i++) {
yield i;
}
yield i;
}
Insert cell
Insert cell
{
function* hasReturnValue() {
yield 'a';
yield 'b';
return 'The result';
}
let finalValue = yield* hasReturnValue();
yield finalValue;
}
Insert cell
Insert cell
html`<div id='my-fun-element'></div>`
Insert cell
document.querySelector('#my-fun-element').innerText = 'What a fun element!'
Insert cell
Insert cell
myElement = html`<div></div>`
Insert cell
myElement.innerText = 'This is my element and I know this will work always and forever'
Insert cell
Insert cell
chart = {
const svg = d3.select(DOM.svg(width, 100));
const x = d3.scaleLinear().range([0, width]);
const y = d3.scaleLinear().range([20, 80]);
svg.append("path")
.datum(d3.range(0, 1, 0.001).map(() => Math.random()))
.attr("fill", "none")
.attr("stroke", "steelblue")
.attr("stroke-width", 1.5)
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round")
.attr("d", d3.line()
.x((d, i) => x(i * 0.001))
.y(y));
return svg.node();
}
Insert cell
viewof randomize = html`<button>Randomize color</button>`
Insert cell
randomize, d3.select(chart).select('path').attr('stroke', `hsl(${Math.random() * 100}, 100%, 50%)`)
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