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

1.1.0 • Public • Published

@queso/debounce

npm license Travis Build Status codecov Try @queso/debounce on RunKit

Part of a library of zero-dependency npm modules that do just one thing.

npm

min + gzip | 199 bytes

source

Creates a debounced function that delays invoking func until after wait milliseconds have elapsed since the last time the debounced function was invoked.

Usage

import debounce from '@queso/debounce'

function calculateLayout() {}
const [debounced, cancel] = debounce(calculateLayout, 100)
window.addEventListener('resize', debounced)
cancel()

Parameters

Name Type Description
func TFunc The function to debounce.
wait number The number of milliseconds to which invocations are debounced.
{ leading, trailing } DebounceOptions Specify invoking on the leading or trailing edge of the timeout (Default is trailing=true).

Type parameters

Name Constraint
TFunc (...args: any[]) => any

Returns

A new debounced function paired with a cancel function.

Return type

[(...args: Parameters<TFunc>) => any, () => void]

Package Sidebar

Install

npm i @queso/debounce

Weekly Downloads

6

Version

1.1.0

License

MIT

Unpacked Size

16.2 kB

Total Files

8

Last publish

Collaborators

  • jedmao