refactor(core): use useNodesInitialized to emit nodesInitialized

This commit is contained in:
braks
2024-02-15 17:46:21 +01:00
committed by Braks
parent fbb3f63134
commit ffdea45af4
2 changed files with 16 additions and 24 deletions
@@ -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
}
@@ -1,38 +1,42 @@
<script lang="ts" setup> <script lang="ts" setup>
import { getCurrentInstance, inject, nextTick, onBeforeUnmount, onMounted, ref, resolveComponent } from 'vue' import { getCurrentInstance, inject, nextTick, onBeforeUnmount, onMounted, ref, resolveComponent, watch } from 'vue'
import { whenever } from '@vueuse/core'
import { NodeWrapper } from '../../components' import { NodeWrapper } from '../../components'
import type { GraphNode, HandleConnectable, NodeComponent } from '../../types' import type { GraphNode, HandleConnectable, NodeComponent } from '../../types'
import { Slots } from '../../context' import { Slots } from '../../context'
import { useVueFlow } from '../../composables' import { useVueFlow } from '../../composables'
import { ErrorCode, VueFlowError } from '../../utils' import { ErrorCode, VueFlowError } from '../../utils'
import { useNodesInitialized } from '../../composables/useNodesInitialized'
const slots = inject(Slots)
const { const {
nodes,
nodesDraggable, nodesDraggable,
nodesFocusable, nodesFocusable,
elementsSelectable, elementsSelectable,
nodesConnectable, nodesConnectable,
getNodes, getNodes,
getNodesInitialized,
areNodesInitialized,
getNodeTypes, getNodeTypes,
updateNodeDimensions, updateNodeDimensions,
emits, emits,
} = useVueFlow() } = useVueFlow()
const nodesInitialized = useNodesInitialized()
const slots = inject(Slots)
const resizeObserver = ref<ResizeObserver>() const resizeObserver = ref<ResizeObserver>()
const instance = getCurrentInstance() const instance = getCurrentInstance()
whenever( watch(
() => areNodesInitialized.value, nodesInitialized,
() => { (initialized) => {
nextTick(() => { if (initialized) {
emits.nodesInitialized(getNodesInitialized.value) nextTick(() => {
}) emits.nodesInitialized(nodes.value)
})
}
}, },
{ immediate: true },
) )
onMounted(() => { onMounted(() => {