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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more