INIT
This commit is contained in:
+19
@@ -0,0 +1,19 @@
|
||||
// oxlint-disable-next-line no-explicit-any
|
||||
export function debounce(fn, wait = 500) {
|
||||
let timeout = null;
|
||||
const debounced = (...args) => {
|
||||
if (timeout !== null) {
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
timeout = setTimeout(() => {
|
||||
fn(...args);
|
||||
}, wait);
|
||||
};
|
||||
debounced.destroy = () => {
|
||||
if (timeout !== null) {
|
||||
clearTimeout(timeout);
|
||||
timeout = null;
|
||||
}
|
||||
};
|
||||
return debounced;
|
||||
}
|
||||
Reference in New Issue
Block a user