grommet
Version:
focus on the essential experience
40 lines (32 loc) • 839 B
JavaScript
;
exports.__esModule = true;
exports.throttle = void 0;
var _this = void 0;
// (C) Copyright 2014-2016 Hewlett Packard Enterprise Development LP
var throttle = function throttle(fn, threshhold, scope) {
if (threshhold === void 0) {
threshhold = 250;
}
if (scope === void 0) {
scope = _this;
}
var last;
var deferTimer;
return function () {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var now = Date.now();
if (last && now < last + threshhold) {
clearTimeout(deferTimer);
deferTimer = setTimeout(function () {
last = now;
fn.apply(scope, args);
}, threshhold);
} else {
last = now;
fn.apply(scope, args);
}
};
};
exports.throttle = throttle;