useDebouncedLoading.ts 473 B

1234567891011121314151617181920
  1. // Copyright (C) 2012-2025 Zammad Foundation, https://zammad-foundation.org/
  2. import { refDebounced } from '@vueuse/shared'
  3. import { type Ref, type ComputedRef, ref } from 'vue'
  4. export const useDebouncedLoading = ({
  5. ms,
  6. isLoading,
  7. }: {
  8. ms?: number
  9. isLoading?: Ref<boolean> | ComputedRef<boolean>
  10. } = {}) => {
  11. const loading = ref(false)
  12. const debouncedLoading = refDebounced(isLoading ?? loading, ms ?? 300)
  13. return {
  14. loading,
  15. debouncedLoading,
  16. }
  17. }