import { throttle } from 'ngwr/utils';
const onScroll = throttle(() => trackScroll(), 100);
window.addEventListener('scroll', onScroll);
destroyRef.onDestroy(() => onScroll.cancel());throttle
Runs a callback at most once every waitMs, on the leading and the trailing edge.
Usage
Call .cancel() on teardown to drop a pending call.
API
| Name | Description | Type | Default |
|---|---|---|---|
throttle(fn, waitMs) | Returns a wrapper that calls fn at most every waitMs, on the leading and trailing edge. .cancel() drops a pending call. | (fn, ms) => WrThrottledFn | — |