debounce

Type:Function
Status:stable
Since:1.0.0
Platform:jsnode
@blackbyte.sugar.shared.function

This utils function allows you to make sure that a function that will normally be called several times, for example during a scroll event, to be called only once after the delay passed

Params

  1. delay*-Number

    A delay in ms to wait between two function calls

  2. fn*-Function

    The function to debounce

Example

import { debounce } from '@blackbyte/sugar/function';
const myDebouncedFn = debounce(1000, () => {
		// my function content that will be
		// executed only once after the 1 second delay
});

document.addEventListener('scroll', (e) => {
		// call my debounced function
		myDebouncedFn();
});

Todo

  • testsnormal