Skip to content

Latest commit

 

History

History

debounce

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

@yeger/debounce

A tiny TypeScript library for debouncing functions.

CI NPM Coverage MIT npm bundle size

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