mirror of
https://github.com/glanceapp/glance.git
synced 2024-12-03 05:45:39 +01:00
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);
|
||
|
}
|