UtilOptional

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.

import { throttle } from 'ngwr/utils';

const onScroll = throttle(() => trackScroll(), 100);
window.addEventListener('scroll', onScroll);
destroyRef.onDestroy(() => onScroll.cancel());

API

NameDescriptionTypeDefault
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—

See also