UNPKG

@jivanf/vest

Version:

Declarative Form Validations Framework

54 lines (49 loc) 2.22 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vest'), require('vest-utils'), require('vestjs-runtime')) : typeof define === 'function' && define.amd ? define(['exports', 'vest', 'vest-utils', 'vestjs-runtime'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.debounce = {}, global.vest, global["vest-utils"], global["vestjs-runtime"])); })(this, (function (exports, vest, vestUtils, vestjsRuntime) { 'use strict'; const isolateType = 'Debounce'; function debounce(callback, delay = 0) { let timeout = null; const f = () => (payload) => new Promise((resolve, reject) => { timeout = setTimeout(() => { let res = false; try { res = callback(payload); } catch (e) { return reject(e); } if (res === false) { return reject(); } return vestUtils.isPromise(res) ? res.then(resolve, reject) : resolve(res); }, delay); }); const i = vestjsRuntime.Isolate.create(isolateType, f, { clearTimeout: () => { if (timeout) { clearTimeout(timeout); } }, }); return i.output; } class IsolateDebounceReconciler { static match(currentNode, historyNode) { return (vestjsRuntime.IsolateSelectors.isIsolateType(currentNode, isolateType) && vestjsRuntime.IsolateSelectors.isIsolateType(historyNode, isolateType)); } static reconcile(current, history) { var _a, _b; (_b = (_a = history === null || history === void 0 ? void 0 : history.data) === null || _a === void 0 ? void 0 : _a.clearTimeout) === null || _b === void 0 ? void 0 : _b.call(_a); return current; } } vest.registerReconciler(IsolateDebounceReconciler); exports.IsolateDebounceReconciler = IsolateDebounceReconciler; exports.default = debounce; Object.defineProperty(exports, '__esModule', { value: true }); })); //# sourceMappingURL=debounce.development.js.map