UtilOptional

debounce

Runs a callback once calls have stopped for waitMs.

Usage

Call .cancel() on teardown to drop a pending call.

import { debounce } from 'ngwr/utils';

const onResize = debounce(() => recalcLayout(), 150);
window.addEventListener('resize', onResize);
destroyRef.onDestroy(() => onResize.cancel());

API

NameDescriptionTypeDefault
debounce(fn, waitMs)Returns a wrapper that calls fn once waitMs pass with no new call. .cancel() drops a pending call.(fn, ms) => WrDebouncedFn—

See also