-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
自定义节点组件调用graph #2257
Comments
Demo好像有点问题 |
循环引用了 |
没找到在哪 |
你是怎么解决的 |
目前只是异常捕获,还没做处理,还没定位到具体哪里 |
好兄弟,解决了后指点指点。 |
同是天涯沦落人,同指点。 |
Hello! React 组件配合 大概的建议做法是将 React 组件函数/类事先注册到全局 // 使用 Graph.registerNode(...) 方法将 React 组件注册到系统中。
Graph.registerNode('my-node', {
inherit: 'react-shape',
x: 200,
y: 150,
width: 150,
height: 100,
component: <MyComponent />
})
// 然后将节点的 shape 属性指定为注册的节点名称
graph.addNode({
x: 40,
y: 40,
width: 100,
height: 40,
shape: 'my-node',
}) 技术细节具体来讲,发生堆栈溢出的原因在于 1)
当我们进行
如果我们采用「事先注册元素」的方法,那么 React 元素就不会在 graph 内部保存(只是保存了它的名字),那么就不会出现这样的循环调用(当然,如果存在其它的循环引用,还是会出现堆栈溢出的). |
下周我试试。 @tonywu6 如君所言,我再试试,兄弟你也试试 @BrickerZou ,有任何情况我来同步 |
试了下,似乎没变化 |
so 注册之后还是使用toJSON()导出数据是吧 |
是的 |
我是用第二个注册到系统的方法,试了下,也不行,还是有那种报错 Graph.registerReactComponent('custom-trigger-cell', <TouchConditionGraphDom/>)
Graph.registerReactComponent('custom-judge-cell', <JudgeConditionGraphDom/>)
Graph.registerReactComponent('custom-execute-cell', <ExecuteActionGraphDom/>) how about you? @BrickerZou |
@BrickerZou 不推荐在 react 组件内部再使用 graph,如果实在有必要的话,可以这样: const graph = node.model.graph; |
This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread. |
Describe the bug
我通过props传递graph到自定义节点组件,进行一些graph的方法,但这似乎不是正确的做法
当我打印出ToJson()时,其props中的graph无限递归。
Your Example Website or App
https://codesandbox.io/s/restless-cdn-21ulm3?file=/src/MyComponent.ts
Steps to Reproduce the Bug or Issue
yarn start
Expected behavior
如何才是正确的做法,自定义节点组件中调用graph的一些方法?
Screenshots or Videos
Platform
Additional context
No response
The text was updated successfully, but these errors were encountered: