3.0.0 • Published 5 years ago

@lavadrop/debounce v3.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

@lavadrop/debounce

npm license Travis Build Status codecov Try @lavadrop/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 '@lavadrop/debounce'

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

Parameters

NameTypeDescription
funcTFuncThe function to debounce.
waitnumberThe number of milliseconds to which invocations are debounced.
{ leading, trailing }DebounceOptionsSpecify invoking on the leading or trailing edge of the timeout (Default is trailing=true).

Type parameters

NameConstraint
TFunc(...args: any[]) => any

Returns

A new debounced function paired with a cancel function.

Return type

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