UNPKG

function-tree

Version:
45 lines (44 loc) 1.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; function createDebounce(time, execution) { function debounce(_ref) { var path = _ref.path; return new Promise(function (resolve) { if (execution.timer) { execution.resolve(path.discard()); clearTimeout(execution.timer); } execution.timer = setTimeout(function () { execution.resolve(path["continue"]()); execution.timer = null; execution.resolve = null; }, time); execution.resolve = resolve; }); } debounce.displayName = 'debounce - ' + time + 'ms'; return debounce; } function debounceFactory(time) { // New execution on every call var execution = { timer: null, resolve: null }; return createDebounce(time, execution); } debounceFactory.shared = function () { // Shared execution var execution = { timer: null, resolve: null }; return function debounceSharedFactory(time) { return createDebounce(time, execution); }; }; var _default = exports["default"] = debounceFactory; //# sourceMappingURL=debounce.js.map