debouncing

πŸ›‚ Debouncing and throttling events module from the Glize library.

Showing:

Popularity

Downloads/wk

7.4K

GitHub Stars

7

Maintenance

Last Commit

2mos ago

Contributors

2

Package

Dependencies

0

License

Apache-2.0

Type Definitions

Built-In

Tree-Shakeable

No?

Categories

Readme

Debouncing Tweet

Build Status License NPM version Website NPM downloads

Debouncing and throttling events module from Glize library.

Usage

npm install debouncing --save
import {debounce, throttle} from 'debouncing';

const onResize = (event) => {
  console.log('height', window.innerHeight);
  console.log('width', window.innerWidth);
};

/**
 * In the debouncing technique, no matter how many times the user fires the 
 * event, the attached function will be executed only after the specified 
 * time once the user stops firing the event.
 * 
 * Returns a function, that, as long as it continues to be invoked, will not
 * be triggered. The function will be called after it stops being called for
 * N milliseconds.
 * @param {!Function} func The function to execute.
 * @param {number=} timeout The timeout in milliseconds.
 * @return {!Function} Returns a function, that, as long as it continues 
 *     to be invoked, will not be triggered.
 */
window.addEventListener('resize', debounce(onResize, 250), false);

/**
 * Throttling is a technique in which, no matter how many times the user 
 * fires the event, the attached function will be executed only once in a 
 * given time interval.
 * 
 * Returns a function, that, as long as it continues to be invoked, will only
 * trigger every N milliseconds.
 * @param {!Function} func The function to execute.
 * @param {number=} timeout The timeout in milliseconds.
 * @return {!Function} Returns a function, that, as long as it continues 
 *     to be invoked, will only trigger every N milliseconds.
 */
window.addEventListener('resize', throttle(onResize, 250), false);

For more information please visit Glize project page.

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100