index.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  2. const require_runtime = require('../../_virtual/_rolldown/runtime.js');
  3. const require_types = require('../../utils/types.js');
  4. let vue = require("vue");
  5. let _vue_shared = require("@vue/shared");
  6. //#region ../../packages/hooks/use-throttle-render/index.ts
  7. const useThrottleRender = (loading, throttle = 0) => {
  8. if (throttle === 0) return loading;
  9. const throttled = (0, vue.ref)((0, _vue_shared.isObject)(throttle) && Boolean(throttle.initVal));
  10. let timeoutHandle = null;
  11. const dispatchThrottling = (timer) => {
  12. if (require_types.isUndefined(timer)) {
  13. throttled.value = loading.value;
  14. return;
  15. }
  16. if (timeoutHandle) clearTimeout(timeoutHandle);
  17. timeoutHandle = setTimeout(() => {
  18. throttled.value = loading.value;
  19. }, timer);
  20. };
  21. const dispatcher = (type) => {
  22. if (type === "leading") if (require_types.isNumber(throttle)) dispatchThrottling(throttle);
  23. else dispatchThrottling(throttle.leading);
  24. else if ((0, _vue_shared.isObject)(throttle)) dispatchThrottling(throttle.trailing);
  25. else throttled.value = false;
  26. };
  27. (0, vue.onMounted)(() => dispatcher("leading"));
  28. (0, vue.watch)(() => loading.value, (val) => {
  29. dispatcher(val ? "leading" : "trailing");
  30. });
  31. return throttled;
  32. };
  33. //#endregion
  34. exports.useThrottleRender = useThrottleRender;
  35. //# sourceMappingURL=index.js.map