Skip to content

debounce

Given a delay and a function returns a new function that will only call the source function after delay milliseconds have passed without any invocations. The debounce function comes with a `cancel` method to cancel delayed `func` invocations and a `flush` method to invoke them immediately.

Usage

const myDebouncedFunc = debounce({ delay: 1000 }, (x) => console.log(x));
myDebouncedFunc(0);
myDebouncedFunc(1); // Logs 1, but not 0

Installation

Terminal window
npx atmx add helper debounce