@erbelion/debounce
v0.0.2
Published
ez debouncer
Downloads
17
Readme
debounce
A simple debouncer.
Installation
yarn
yarn add @erbelion/debounce
npm
npm i @erbelion/debounce
Usage
import debounce from '@erbelion/debounce'
const refresh = debounce(() => {
doSomething()
}, 1000) // delay in milliseconds
refresh() // invokes doSomething() after 1000ms, unless called again
refresh.invoke() // same as above
refresh.invokeNow() // invoke refresh() immediately
refresh.cancel() // cancels refresh() if it has been invoked
refresh.overwrite(() => {
doSomethingElse()
}, 2000) // cancels refresh() and overwrites the debouncer
const refresh = debounce() // init without callable function and delay
refresh.reset() // cancels refresh(), resets callable function and delay
refresh.overwrite() // same as above