UNPKG

839 BJavaScriptView Raw
1"use strict";
2
3exports.__esModule = true;
4exports.throttle = void 0;
5
6var _this = void 0;
7
8// (C) Copyright 2014-2016 Hewlett Packard Enterprise Development LP
9var throttle = function throttle(fn, threshhold, scope) {
10 if (threshhold === void 0) {
11 threshhold = 250;
12 }
13
14 if (scope === void 0) {
15 scope = _this;
16 }
17
18 var last;
19 var deferTimer;
20 return function () {
21 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
22 args[_key] = arguments[_key];
23 }
24
25 var now = Date.now();
26
27 if (last && now < last + threshhold) {
28 clearTimeout(deferTimer);
29 deferTimer = setTimeout(function () {
30 last = now;
31 fn.apply(scope, args);
32 }, threshhold);
33 } else {
34 last = now;
35 fn.apply(scope, args);
36 }
37 };
38};
39
40exports.throttle = throttle;
\No newline at end of file