Skip to content

Debounce

Limits the rate at which a given function can be called over time.

View in BitBucket

Parameters

int - delay

milliseconds to delay before running fn

function - fn

the function to run after the delay

Return Value

A function, decorated with the debounce logic.

Example Usage

import debounce from '@mvps-genesis/debounce';

// storing as a variable to be called later
const debounced = debounce( 200, () => { console.log( 'Fire!' ) } );
debounced();

// self-executing
debounced( 200, () => { console.log( 'Fire!' ) } )();