index.js 754 B

1234567891011121314151617181920212223242526272829303132
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. const useThrottleRender = (loading, throttle = 0) => {
  5. if (throttle === 0)
  6. return loading;
  7. const throttled = vue.ref(false);
  8. let timeoutHandle = null;
  9. const dispatchThrottling = () => {
  10. if (timeoutHandle) {
  11. clearTimeout(timeoutHandle);
  12. }
  13. timeoutHandle = setTimeout(() => {
  14. throttled.value = loading.value;
  15. }, throttle);
  16. };
  17. vue.onMounted(dispatchThrottling);
  18. vue.watch(() => loading.value, (val) => {
  19. if (val) {
  20. dispatchThrottling();
  21. } else {
  22. throttled.value = val;
  23. }
  24. });
  25. return throttled;
  26. };
  27. exports.useThrottleRender = useThrottleRender;
  28. //# sourceMappingURL=index.js.map