UNPKG

vue-admin-core

Version:
41 lines (38 loc) 1.03 kB
import { throttle } from 'lodash-es'; const useThrottlePlugin = (fetchInstance, { throttleWait, throttleLeading, throttleTrailing }) => { let throttled; const options = {}; if (throttleLeading !== void 0) { options.leading = throttleLeading; } if (throttleTrailing !== void 0) { options.trailing = throttleTrailing; } if (throttleWait) { const _originRunAsync = fetchInstance.runAsync.bind(fetchInstance); throttled = throttle( (callback) => { callback(); }, throttleWait, options ); fetchInstance.runAsync = (...args) => { return new Promise((resolve, reject) => { throttled == null ? void 0 : throttled(() => { _originRunAsync(...args).then(resolve).catch(reject); }); }); }; } if (!throttleWait) { return {}; } return { onCancel: () => { throttled == null ? void 0 : throttled.cancel(); } }; }; export { useThrottlePlugin as default }; //# sourceMappingURL=useThrottlePlugin.mjs.map