refactor(core): use useNodesInitialized to emit nodesInitialized

This commit is contained in:
braks
2024-02-05 21:30:42 +01:00
committed by Braks
parent fbb3f63134
commit ffdea45af4
2 changed files with 16 additions and 24 deletions

View File

@@ -1,12 +0,0 @@
/**
* Composable for getting the visible node ids from the store.
*
* @internal
* @param onlyRenderVisible
* @returns array with visible node ids
*/
export function useVisibleNodeIds(onlyRenderVisible: boolean) {
const nodeIds = useStore(useCallback(selector(onlyRenderVisible), [onlyRenderVisible]), shallow)
return nodeIds
}

View File

@@ -1,38 +1,42 @@
<script lang="ts" setup>
import { getCurrentInstance, inject, nextTick, onBeforeUnmount, onMounted, ref, resolveComponent } from 'vue'
import { whenever } from '@vueuse/core'
import { getCurrentInstance, inject, nextTick, onBeforeUnmount, onMounted, ref, resolveComponent, watch } from 'vue'
import { NodeWrapper } from '../../components'
import type { GraphNode, HandleConnectable, NodeComponent } from '../../types'
import { Slots } from '../../context'
import { useVueFlow } from '../../composables'
import { ErrorCode, VueFlowError } from '../../utils'
const slots = inject(Slots)
import { useNodesInitialized } from '../../composables/useNodesInitialized'
const {
nodes,
nodesDraggable,
nodesFocusable,
elementsSelectable,
nodesConnectable,
getNodes,
getNodesInitialized,
areNodesInitialized,
getNodeTypes,
updateNodeDimensions,
emits,
} = useVueFlow()
const nodesInitialized = useNodesInitialized()
const slots = inject(Slots)
const resizeObserver = ref<ResizeObserver>()
const instance = getCurrentInstance()
whenever(
() => areNodesInitialized.value,
() => {
nextTick(() => {
emits.nodesInitialized(getNodesInitialized.value)
})
watch(
nodesInitialized,
(initialized) => {
if (initialized) {
nextTick(() => {
emits.nodesInitialized(nodes.value)
})
}
},
{ immediate: true },
)
onMounted(() => {