nit
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
* - **AbstractNodeProps<TData>** — Typed props (id, data, width?, height?, selected?) for your node.
|
||||
* - **useAbstractNode(id, data)** — Flow context plus helpers: nodes, edges, setNodes, setEdges,
|
||||
* updateData(partial), incomingEdges, outgoingEdges, sourceIds, targetIds. Calling updateData()
|
||||
* also reports this node as a trigger for connection path (lifecycle "trigger").
|
||||
* also marks this node as a connection-path trigger so edges update on data changes.
|
||||
* - **createAbstractNodeComponent(displayName, Component)** — Wraps with memo + nodePropsAreEqual.
|
||||
*
|
||||
* **Node lifecycle / connection status:** Nodes that can be updating, paused, or in error should
|
||||
@@ -15,7 +15,7 @@
|
||||
* component, then export const MyNode = createAbstractNodeComponent('MyNode', MyNodeComponent).
|
||||
*/
|
||||
|
||||
import React, { useCallback, useContext, useMemo } from 'react'
|
||||
import React, { useCallback, useContext, useMemo, useRef } from 'react'
|
||||
import { GraphContext, ConnectionPathContext } from './flowContext'
|
||||
import { nodePropsAreEqual } from './flowUtils'
|
||||
import type { AppNode } from './nodeTypes'
|
||||
@@ -82,12 +82,13 @@ export function useAbstractNode<TData = Record<string, unknown>>(
|
||||
): AbstractNodeContext<TData> {
|
||||
const graphCtx = useContext(GraphContext)
|
||||
const pathCtx = useContext(ConnectionPathContext)
|
||||
const addTriggerRef = useRef(pathCtx?.addConnectionPathTrigger)
|
||||
addTriggerRef.current = pathCtx?.addConnectionPathTrigger
|
||||
const nodes = graphCtx?.graphRef?.current?.nodes ?? []
|
||||
const edges = graphCtx?.edges ?? []
|
||||
const setNodes = graphCtx?.setNodes
|
||||
const setEdges = graphCtx?.setEdges
|
||||
|
||||
const addConnectionPathTrigger = pathCtx?.addConnectionPathTrigger
|
||||
const updateData = useCallback(
|
||||
(partial: Partial<TData>) => {
|
||||
if (!setNodes) return
|
||||
@@ -96,9 +97,9 @@ export function useAbstractNode<TData = Record<string, unknown>>(
|
||||
n.id === id ? { ...n, data: { ...(n.data as object), ...partial } } : n
|
||||
) as AppNode[]
|
||||
)
|
||||
addConnectionPathTrigger?.(id)
|
||||
addTriggerRef.current?.(id)
|
||||
},
|
||||
[id, setNodes, addConnectionPathTrigger]
|
||||
[id, setNodes]
|
||||
)
|
||||
|
||||
const incomingEdges = useMemo(
|
||||
|
||||
Reference in New Issue
Block a user