Line data Source code
1 : import { get, useAsyncState } from '@vueuse/core'
2 : import type { Ref } from 'vue'
3 :
4 : import { useComfyRegistryStore } from '@/stores/comfyRegistryStore'
5 : import type { UseNodePacksOptions } from '@/platform/customNodes/manager/types/comfyManagerTypes'
6 :
7 : /**
8 : * Handles fetching node packs from the registry given a list of node pack IDs
9 : */
10 2356 : export const useNodePacks = (
11 : packsIds: string[] | Ref<string[]>,
12 : options: UseNodePacksOptions = {}
13 : ) => {
14 9505 : const { immediate = false } = options
15 9505 : const { getPacksByIds } = useComfyRegistryStore()
16 :
17 9505 : const fetchPacks = () => getPacksByIds.call(get(packsIds).filter(Boolean))
18 :
19 9505 : const {
20 : isReady,
21 : isLoading,
22 : error,
23 : execute,
24 : state: nodePacks
25 : } = useAsyncState(fetchPacks, [], {
26 : immediate
27 : })
28 :
29 9505 : const cleanup = () => {
30 560 : getPacksByIds.cancel()
31 560 : isReady.value = false
32 560 : isLoading.value = false
33 : }
34 :
35 9505 : return {
36 : error,
37 : isLoading,
38 : isReady,
39 : nodePacks,
40 : startFetch: execute,
41 : cleanup
42 : }
43 : }
|