UNPKG

vue-hooks-plus

Version:
29 lines (28 loc) 806 B
"use strict"; const throttle = require("lodash-es/throttle"); const vue = require("vue"); const _interopDefaultLegacy = (e) => e && typeof e === "object" && "default" in e ? e : { default: e }; const throttle__default = /* @__PURE__ */ _interopDefaultLegacy(throttle); function useThrottleFn(fn, options) { var _a; const fnRef = vue.ref(fn); const wait = (_a = options == null ? void 0 : options.wait) != null ? _a : 1e3; const throttled = vue.computed( () => throttle__default.default( (...args) => { return fnRef.value([...args]); }, wait, options ) ); vue.onUnmounted(() => { throttled.value.cancel(); }); return { run: throttled, cancel: throttled.value.cancel, flush: throttled.value.flush }; } module.exports = useThrottleFn;