@ryusei/code
Version:
<div align="center"> <a href="https://code.ryuseijs.com"> <img alt="RyuseiCode" src="https://code.ryuseijs.com/images/svg/logo.svg" width="70"> </a>
19 lines (16 loc) • 537 B
text/typescript
import { AnyFunction } from '@ryusei/code';
import { Throttle, throttle } from '../throttle/throttle';
/**
* Implements the `throttle` function via requestAnimationFrame.
*
* @param func - A function to throttle.
* @param initialCall - Optional. Determines whether to call the function initially.
*
* @return A throttled function.
*/
export function rafThrottle<F extends AnyFunction = AnyFunction>(
func: F,
initialCall?: boolean
): Throttle<F> {
return throttle( func, 0, initialCall, false, true );
}