index.mjs 670 B

12345678910111213141516171819202122232425262728
  1. import { ref, onMounted, watch } from 'vue';
  2. const useThrottleRender = (loading, throttle = 0) => {
  3. if (throttle === 0)
  4. return loading;
  5. const throttled = ref(false);
  6. let timeoutHandle = 0;
  7. const dispatchThrottling = () => {
  8. if (timeoutHandle) {
  9. clearTimeout(timeoutHandle);
  10. }
  11. timeoutHandle = window.setTimeout(() => {
  12. throttled.value = loading.value;
  13. }, throttle);
  14. };
  15. onMounted(dispatchThrottling);
  16. watch(() => loading.value, (val) => {
  17. if (val) {
  18. dispatchThrottling();
  19. } else {
  20. throttled.value = val;
  21. }
  22. });
  23. return throttled;
  24. };
  25. export { useThrottleRender };
  26. //# sourceMappingURL=index.mjs.map