UNPKG

@geogirafe/lib-geoportal

Version:

GeoGirafe is a flexible application to build online geoportals.

21 lines (20 loc) 540 B
/** * @param {T} func The function to debounce. * @param {number} wait The wait time in ms. * @returns {T} The wrapper function. * @template T */ export function debounce(func, wait) { let timeout = null; return function (...args) { const later = () => { timeout = null; // @ts-expect-error can't know type of T func.apply(this, args); }; if (timeout !== null) { clearTimeout(timeout); } timeout = window.setTimeout(later, wait); }; }