UNPKG

823 BJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = debounce;
7
8// Corresponds to 10 frames at 60 Hz.
9// A few bytes payload overhead when lodash/debounce is ~3 kB and debounce ~300 B.
10function debounce(func) {
11 var wait = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 166;
12 var timeout;
13
14 function debounced() {
15 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
16 args[_key] = arguments[_key];
17 }
18
19 // eslint-disable-next-line consistent-this
20 var that = this;
21
22 var later = function later() {
23 func.apply(that, args);
24 };
25
26 clearTimeout(timeout);
27 timeout = setTimeout(later, wait);
28 }
29
30 debounced.clear = function () {
31 clearTimeout(timeout);
32 };
33
34 return debounced;
35}
\No newline at end of file