UNPKG

vue-admin-core

Version:
53 lines (48 loc) 1.31 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var lodashEs = require('lodash-es'); var vue = require('vue'); const useDebouncePlugin = (fetchInstance, { debounceWait, debounceLeading, debounceTrailing, debounceMaxWait }) => { let debounced; const options = {}; if (debounceLeading !== void 0) { options.leading = debounceLeading; } if (debounceTrailing !== void 0) { options.trailing = debounceTrailing; } if (debounceMaxWait !== void 0) { options.maxWait = debounceMaxWait; } if (debounceWait) { const _originRunAsync = fetchInstance.runAsync.bind(fetchInstance); debounced = lodashEs.debounce( (callback) => { callback(); }, debounceWait, options ); fetchInstance.runAsync = (...args) => { return new Promise((resolve, reject) => { debounced(() => { _originRunAsync(...args).then(resolve).catch(reject); }); }); }; vue.onUnmounted(() => { debounced.cancel(); fetchInstance.runAsync = _originRunAsync; }); } if (!debounceWait) { return {}; } return { onCancel: () => { debounced == null ? void 0 : debounced.cancel(); } }; }; exports.default = useDebouncePlugin; //# sourceMappingURL=useDebouncePlugin.js.map