@geogirafe/lib-geoportal
Version:
GeoGirafe is a flexible application to build online geoportals.
22 lines (21 loc) • 579 B
JavaScript
// SPDX-License-Identifier: Apache-2.0
/**
* @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);
};
}