debounce-execution
Debounce will collapse multiple requests (if any) for a named task
into one invocation which will execute after the given wait time has passed.
By default the latest request for a task will be executed after the given wait time,
but it is possible to execute the first request and block any future requests until
the given wait time has passed.
Installation
$ npm install debounce-execution --save
Changelog
v1.0.7
- BREAKING CHANGE: new syntax. Removed 'job names' in favor of equality checking.
- Fixed a bug where the same function could be called multiple times.
v1.0.6
- Added optional Flow typings and built with rollup instead. For a typed version, import from
debounce-execution/typed
instead. - Added an optional version with es-module exports instead of umd. For the native version, import from
debounce-execution/native
instead.
Examples
Debounce sports one method: debounce(func: function, waitTime?: number = 0, immediate?: boolean = false): void
.
This allows you to do:
let scrollhandler = () => debounce(onScroll, 200);
container.addEventListener("scroll", scrollHandler);
function onScroll () {
}
If immediate is true, the first request is executed and then any requests within the given waitTime will be blocked:
let touchStartHandler = () => debounce(onTouchStart, 100, true);
container.addEventListener("touchstart", touchStartHandler);
function onTouchStart (e) {
}
Usage
Simply do npm install debounce-execution --save
;
And then all that's left is to import what you want:
import Debounce from "debounce-execution";
import Debounce from "debounce-execution/typed"
import Debounce from "debounce-execution/native"
The standard version works with amd
, umd
, commonjs
and iife
:
const Debounce = require("debounce-execution");
License
Copyright (c) 2016 Dlmma IVS. Released under the MIT license.