2023-04-09 22:49:50 +02:00
|
|
|
/*
|
|
|
|
|
* SPDX-License-Identifier: GPL-3.0
|
|
|
|
|
* Vencord Desktop, a desktop app aiming to give you a snappier Discord Experience
|
|
|
|
|
* Copyright (c) 2023 Vendicated and Vencord contributors
|
|
|
|
|
*/
|
|
|
|
|
|
2023-04-05 20:01:31 +02:00
|
|
|
export function debounce<T extends Function>(func: T, delay = 300): T {
|
|
|
|
|
let timeout: NodeJS.Timeout;
|
|
|
|
|
return function (...args: any[]) {
|
|
|
|
|
clearTimeout(timeout);
|
2023-04-09 22:49:50 +02:00
|
|
|
timeout = setTimeout(() => {
|
|
|
|
|
func(...args);
|
|
|
|
|
}, delay);
|
2023-04-05 20:01:31 +02:00
|
|
|
} as any;
|
|
|
|
|
}
|