feat: introdce store
This commit is contained in:
@@ -15,8 +15,9 @@
|
||||
* component, then export const MyNode = createAbstractNodeComponent('MyNode', MyNodeComponent).
|
||||
*/
|
||||
|
||||
import React, { useCallback, useContext, useMemo, useRef } from 'react'
|
||||
import { GraphContext, ConnectionPathContext } from './flowContext'
|
||||
import React, { useCallback, useContext, useMemo } from 'react'
|
||||
import { GraphContext } from './flowContext'
|
||||
import { dispatchCanvasCommand } from '@/app/canvas/canvasStore'
|
||||
import { nodePropsAreEqual } from './flowUtils'
|
||||
import type { AppNode } from './nodeTypes'
|
||||
|
||||
@@ -81,9 +82,6 @@ export function useAbstractNode<TData = Record<string, unknown>>(
|
||||
data: TData
|
||||
): 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
|
||||
@@ -97,7 +95,7 @@ export function useAbstractNode<TData = Record<string, unknown>>(
|
||||
n.id === id ? { ...n, data: { ...(n.data as object), ...partial } } : n
|
||||
) as AppNode[]
|
||||
)
|
||||
addTriggerRef.current?.(id)
|
||||
dispatchCanvasCommand({ type: 'path/addTrigger', payload: id })
|
||||
},
|
||||
[id, setNodes]
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user