@types/throttle-debounce

  • Version 5.0.2
  • Published
  • 6.48 kB
  • No dependencies
  • MIT license

Install

npm i @types/throttle-debounce
yarn add @types/throttle-debounce
pnpm add @types/throttle-debounce

Overview

TypeScript definitions for throttle-debounce

Index

Functions

function debounce

debounce: <T extends (...args: any[]) => any>(
delay: number,
callback: T,
options?: DebounceOptions
) => debounce<T>;
  • Debounce execution of a function. Debouncing, unlike throttling, guarantees that a function is only executed a single time, either at the very beginning of a series of calls, or at the very end.

    Parameter delay

    A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.

    Parameter callback

    A function to be executed after delay milliseconds. The this context and all arguments are passed through, as-is, to callback when the debounced-function is executed.

    Parameter options

    An object to configure options.

    Parameter

    options.atBegin If atBegin is false or unspecified, callback will only be executed delay milliseconds after the last debounced-function call. If atBegin is true, callback will be executed only at the first debounced-function call. (After the throttled-function has not been called for delay milliseconds, the internal counter is reset).

    A new, debounced function.

function throttle

throttle: <T extends (...args: any[]) => any>(
delay: number,
callback: T,
options?: ThrottleOptions
) => throttle<T>;
  • Throttle execution of a function. Especially useful for rate limiting execution of handlers on events like resize and scroll.

    Parameter delay

    A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.

    Parameter callback

    A function to be executed after delay milliseconds. The this context and all arguments are passed through, as-is, to callback when the throttled-function is executed.

    Parameter options

    An object to configure options.

    Parameter

    options.noTrailing Optional, defaults to false. If noTrailing is true, callback will only execute every delay milliseconds while the throttled-function is being called. If noTrailing is false or unspecified, callback will be executed one final time after the last throttled-function call. (After the throttled-function has not been called for delay milliseconds, the internal counter is reset)

    Parameter

    options.noLeading Optional, defaults to false. If noLeading is false, the first throttled-function call will execute callback immediately. If noLeading is true, the first the callback execution will be skipped. It should be noted that callback will never executed if both noLeading = true and noTrailing = true.

    Parameter

    options.debounceMode If debounceMode is true (at begin), schedule callback to execute after delay ms. If debounceMode is false (at end), schedule callback to execute after delay ms.

    A new, throttled, function.

Type Aliases

type debounce

type debounce<T extends (...args: any[]) => any> = NoReturn<T> & Cancel;

    type throttle

    type throttle<T extends (...args: any[]) => any> = NoReturn<T> & Cancel;

      Package Files (1)

      Dependencies (0)

      No dependencies.

      Dev Dependencies (0)

      No dev dependencies.

      Peer Dependencies (0)

      No peer dependencies.

      Badge

      To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

      You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/throttle-debounce.

      • Markdown
        [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/throttle-debounce)
      • HTML
        <a href="https://www.jsdocs.io/package/@types/throttle-debounce"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>