@yeger/debounce
v2.0.10
Published
A tiny TypeScript library for debouncing functions.
Downloads
32,478
Readme
Features
- ✨ Debounce any callback. Usefull for preventing flickering when using
ResizeObserver
. - ⏱️ Optional delays for callback invocations.
- 🐭 Tiny.
Installation
# yarn
$ yarn add @yeger/debounce
# npm
$ npm install @yeger/debounce
Usage
import { debounce } from '@yeger/debounce'
// Take an existing function
function resize(): void {
// ...
}
// Debounce it using the library
const debouncedResize = debounce(() => resize())
// And use the debounced function
const resizeObserver = new ResizeObserver(debouncedResize)
Optionally, a delay for the invocation of the debounced method can be passed.
const debouncedResize = debounce(() => resize(), 200)
Development
# install dependencies
$ pnpm install
# build for production
$ pnpm build
# lint project files
$ pnpm lint
# run tests
$ pnpm test
License
MIT - Copyright © Jan Müller