Calls a function at most once per wait ms.
import { throttle } from 'mxs';
window.addEventListener('scroll', throttle(updatePosition, { wait: 100 }));throttle<Args>(fn: (...args: Args) => void, options: { wait: number; signal?: AbortSignal }): Throttled<Args>| Option | Description |
|---|---|
wait |
Minimum time in ms between calls. |
signal |
Aborting cancels the pending call and ignores later ones. |
- The first call runs immediately.
- Calls during the window are collapsed. The last one runs when the window ends.
canceldrops the pending call.flushruns it now.