Published
Edited
Aug 8, 2018
3 forks
Importers
18 stars
Insert cell
Insert cell
Insert cell
Insert cell
input
Insert cell
Insert cell
debounce(viewof input)
Insert cell
Insert cell
function debounce(input, delay = 1000) {
return Generators.observe(notify => {
let timer = null;
let value;

// On input, check if we recently reported a value.
// If we did, do nothing and wait for a delay;
// otherwise, report the current value and set a timeout.
function inputted() {
if (timer !== null) return;
notify(value = input.value);
timer = setTimeout(delayed, delay);
}

// After a delay, check if the last-reported value is the current value.
// If it’s not, report the new value.
function delayed() {
timer = null;
if (value === input.value) return;
notify(value = input.value);
}

input.addEventListener("input", inputted), inputted();
return () => input.removeEventListener("input", inputted);
});
}
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