Line data Source code
1 : import { useEventListener } from '@vueuse/core'
2 : import type { ComputedRef } from 'vue'
3 : import { computed, shallowRef } from 'vue'
4 :
5 : import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode'
6 : import { app } from '@/scripts/app'
7 :
8 : /** The node `resolve` returns, resolved again each time the root graph is configured. */
9 108 : export function useLiveGraphNode(
10 : resolve: () => LGraphNode | null | undefined
11 : ): ComputedRef<LGraphNode | null> {
12 108 : const node = shallowRef(resolve() ?? null)
13 108 : useEventListener(
14 : () => app.rootGraphOrUndefined?.events,
15 : 'configured',
16 : () => (node.value = resolve() ?? null)
17 : )
18 108 : return computed(() => node.value)
19 : }
|