Class Debounce

Enable debouncing of callbacks, with various styles of debounce supported in DebounceStyle (see its docs for debounce style details). A callback can be provided on construction or to the .execute() method.

import {Debounce} from '@augment-vir/common';

const debounce = new Debounce(
DebounceStyle.FirstThenWait,
{
milliseconds: 500,
},
// callback can optionally be provided on construction
() => {
console.log('called');
},
);

debounce.execute();
// providing a callback in `.execute()` permanently overrides the callback provided in construction.
debounce.execute(() => {});

@augment-vir/common

Constructors

Properties

callback?: (() => MaybePromise<void>)

Set the callback to be triggered on .execute(). If this is not set, the callback to be called can be passed in .execute() instead.

debounceDuration: AnyDuration

Duration between debounces.

debounceStyle: DebounceStyle

Debounce style. See DebounceStyle for more details.

nextCallTimestamp: number = 0

Methods