@parcel/utils
Version:
Blazing fast, zero configuration web application bundler
20 lines (16 loc) • 362 B
JavaScript
// @flow strict-local
export default function debounce<TArgs: Array<mixed>>(
fn: (...args: TArgs) => mixed,
delay: number,
): (...args: TArgs) => void {
let timeout;
return function (...args: TArgs) {
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(() => {
timeout = null;
fn(...args);
}, delay);
};
}