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
Examples
Debounce sports one public static method: debounce(jobName: String, func: function, ?waitTime: number, ?immediate: boolean)
.
This allows you to do:
let scrollhandler = Debounce.debounce("collapseScroll", 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.debounce("collapseTouchStart", 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";
or
const Debounce = require("debounce-execution");
License
Copyright (c) 2016 Dlmma IVS. Released under the MIT license.