react-cqtoolbox
Version:
[![Travis][build-badge]][build] [![npm package][npm-badge]][npm] [![Coveralls][coveralls-badge]][coveralls]
28 lines (26 loc) • 635 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = throttle;
function throttle(fn, threshhold, scope) {
threshhold || (threshhold = 250);
var last = void 0,
deferTimer = void 0;
return function () {
var context = scope || this;
var now = Date.now(),
args = arguments;
if (last && now < last + threshhold) {
// hold on to it
clearTimeout(deferTimer);
deferTimer = setTimeout(function () {
last = now;
fn.apply(context, args);
}, threshhold);
} else {
last = now;
fn.apply(context, args);
}
};
}