All files / src/stores loading.ts

100% Statements 27/27
100% Branches 7/7
100% Functions 3/3
100% Lines 27/27

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69  2x 2x                                                               2x 2x 2x 13x 13x   13x   17x   17x 17x 17x   13x   12x 12x   13x 1x 1x   13x 13x 13x   13x 13x 13x 13x 13x 2x    
// region Dependency Injection
import {defineStore} from "pinia";
import {computed, ref} from "vue";
// endregion Dependency Injection
 
// region Component Injection
// endregion Component Injection
 
// region interface
// endregion interface
 
// region constants
// endregion constants
 
// region props
// endregion props
 
// region variable
// endregion variable
 
// region properties
// endregion properties
 
// region emits
// endregion emits
 
// region validator
// endregion validator
 
// region methods
// endregion methods
 
// region export
 
export const useLoadingStore = defineStore(
  'loading',
  () => {
    const tokens = ref(new Set<symbol>())
    const isLoading = computed(() => tokens.value.size > 0)
 
    function start(tag?: string) {
      // console.log(`store start loading: ${JSON.stringify(tag)}`)
      const t = Symbol(tag ?? 'loading')
      // console.log(`store start loading: ${JSON.stringify(t)}`)
      tokens.value.add(t)
      return t
    }
 
    function stop(token?: symbol) {
      // console.log(`store stop loading: ${JSON.stringify(token)}`)
      if (token) tokens.value.delete(token)
    }
 
    function reset() {
      tokens.value.clear()
    }
 
    return {
      tokens,
      isLoading,
 
      start,
      stop,
      reset
    }
  }
)
// endregion export