Published
Edited
Oct 6, 2020
Insert cell
Insert cell
d3 = require('d3');
Insert cell
html `<button id="coolButton">Click me</button>`
Insert cell
viewof ButtonHandler =
{
d3.select('#coolButton')
.on('click', () =>
{
console.log('functionStart');
let pointlessComputation = 0;
for (let i = 0; i < 1000000000; i++)
{
// takes a couple of seconds on my machine
pointlessComputation += i;
}
console.log('functionEnd');
});
}
Insert cell
html `<button id="coolAsyncButton">Click me (async)</button>`
Insert cell
viewof ButtonHandlerAsync =
{
d3.select('#coolAsyncButton')
.on('click', () =>
{
console.log('functionStart');
setTimeout(() =>
{
// After 2000 milliseconds log 'funtionEnd'
console.log('functionEnd');
}, 2000);
});
}
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