mirror of
https://github.com/glanceapp/glance.git
synced 2024-12-02 05:14:59 +01:00
b0c4d70628
Also move utils to new file
26 lines
684 B
JavaScript
26 lines
684 B
JavaScript
export function throttledDebounce(callback, maxDebounceTimes, debounceDelay) {
|
|
let debounceTimeout;
|
|
let timesDebounced = 0;
|
|
|
|
return function () {
|
|
if (timesDebounced == maxDebounceTimes) {
|
|
clearTimeout(debounceTimeout);
|
|
timesDebounced = 0;
|
|
callback();
|
|
return;
|
|
}
|
|
|
|
clearTimeout(debounceTimeout);
|
|
timesDebounced++;
|
|
|
|
debounceTimeout = setTimeout(() => {
|
|
timesDebounced = 0;
|
|
callback();
|
|
}, debounceDelay);
|
|
};
|
|
};
|
|
|
|
export function isElementVisible(element) {
|
|
return !!(element.offsetWidth || element.offsetHeight || element.getClientRects().length);
|
|
}
|