A tiny TypeScript library for debouncing functions.
- ✨ Debounce any callback. Usefull for preventing flickering when using
ResizeObserver
. - ⏱️ Optional delays for callback invocations.
- 🐭 Tiny.
# yarn
$ yarn add @yeger/debounce
# npm
$ npm install @yeger/debounce
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)
# install dependencies
$ pnpm install
# build for production
$ pnpm build
# lint project files
$ pnpm lint
# run tests
$ pnpm test
MIT - Copyright © Jan Müller