1.0.0 • Published 4 years ago

un-debounce v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

un-debounce

This is an alternative implementation to the 'debounce' npm package.

Why another debounce?

The popular 'debounce' package uses an older implementation of Underscore's debounce. The older version can leave misleading artifacts in JavaScript profiler, making it difficult to tell which debounced invocations were executed and which were not.

This version is written in TypeScript and distributed as an ES6 module, which makes it suitable for newer projects. All relevant unit tests from Underscore were ported over to ensure that it can be used as a drop-in replacement.

Also included is a flush method similar to the one found in Lodash.

Install

You can install this package from NPM: npm install un-debounce

Then use it as an ES6 module: import debounce from 'un-debounce';

Arguments

func (Function): The function to debounce.

wait=0 (number): The number of milliseconds to delay.

immediate=false (Object): The options object.

Returns

(Function): Returns the new debounced function.

Example

// Avoid costly calculations while the window size is in flux.
jQuery(window).on('resize', debounce(calculateLayout, 150));

// Invoke `sendMail` when clicked, debouncing subsequent calls.
jQuery(element).on('click', debounce(sendMail, 300, true));

// Cancel the trailing debounced invocation.
jQuery(window).on('popstate', debounced.cancel);

// Invoke any pending invocations immediately
debounced.flush();
1.0.0

4 years ago

0.0.3

4 years ago

0.0.2

5 years ago

0.0.1

5 years ago

0.0.0

5 years ago