1
0
Fork 0

Added Statistics calculation

Statistics now show calculated values
This commit is contained in:
Techognito 2025-09-04 17:30:00 +02:00
parent fe87374e47
commit fc0f69dacb
2147 changed files with 141321 additions and 39 deletions

View file

@ -0,0 +1,33 @@
/**
* Creates a throttled function that only invokes `fn` at most once per animation frame.
*
* @example
* ```ts
* const throttled = rafThrottle((value: number) => console.log(value));
* window.addEventListener('scroll', (e) => throttled(e.target.scrollTop));
* ```
*
* @param fn Callback function
* @return The `requestAnimationFrame` throttled function
*/
export function rafThrottle(fn) {
let lastArgs;
let rafRef;
const later = () => {
rafRef = null;
fn(...lastArgs);
};
function throttled(...args) {
lastArgs = args;
if (!rafRef) {
rafRef = requestAnimationFrame(later);
}
}
throttled.clear = () => {
if (rafRef) {
cancelAnimationFrame(rafRef);
rafRef = null;
}
};
return throttled;
}