UNPKG

function-tree

Version:
39 lines 1.02 kB
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); }; }; export default debounceFactory; //# sourceMappingURL=debounce.js.map