@erbelion/debounce
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

debounce

Get package from npm Downloads views likes

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

Package Sidebar

Install

npm i @erbelion/debounce

Weekly Downloads

5

Version

0.0.2

License

MIT

Unpacked Size

9.78 kB

Total Files

10

Last publish

Collaborators

  • erbelion