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

3.0.0 • Public • Published

@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

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]

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i @lavadrop/debounce

      Weekly Downloads

      2

      Version

      3.0.0

      License

      MIT

      Unpacked Size

      17.4 kB

      Total Files

      8

      Last publish

      Collaborators

      • jedmao