/ts-debounce

TypeScript implementation of debounce function.

Primary LanguageTypeScriptMIT LicenseMIT

TypeScript implementation of debounce function

Build Status npm npm bundle size (minified + gzip) npm type definitions David David

All Contributors

Debounce create a new function g, which when called will delay the invocation of the original function f until n milliseconds after it was last called.

It's very useful for scenarios where it's better to limit the number of times the function is called. E.g. think of search input which fetches data from API. It's enough display search results after user stopped entering characters for some time.

Function arguments

import { debounce } from 'ts-debounce';

const debouncedFunction = debounce(originalFunction, waitMilliseconds, options);
  • originalFunction
    • the function which we want to debounce
  • waitMilliseconds
    • how many seconds must pass after most recent function call, for the original function to be called
  • options
    • options object supports now one argument
    • isImmediate
      • if set to true then originalFunction will be called immediately, but on subsequent calls of the debounced function original function won't be called, unless waitMilliseconds passed after last call

Credits & inspiration

This implementation is based upon following sources:

Compability

  • version 2 - TypeScript 3.3
  • version 1 - TypeScript 2.0

Contributors


Zac

💻

Karol Majewski

💻

Fabien Rogeret

💻

Iman

💻