【自学】4.24 Pubsub/x6

本文探讨了PubSub发布订阅模式与Redux状态管理的相似性,并展示了如何使用PubSub进行消息传递。同时,详细阐述了在X6中注册和使用React组件的过程,包括组件注册代码示例及实际创建节点的应用。通过这种方式,读者可以更好地理解和应用这两种技术。

自学

  • Pubsub发布和订阅 其实和redux差不多
PubSub.publish(data?.operatorType || 'message', data)
PubSub.subscribe('profiler', (_, message) => {})
  • x6注册React组件
Object.keys(operators).forEach(operatorName => {
  const Component = operators[operatorName];
  Graph.registerReactComponent(
    operatorName,
    (node) => <AntdConfigProvider><AppProvider><Provider><Component node={node} /></Provider></AppProvider></AntdConfigProvider>
  )
})

//使用
   const node = graph.createNode({
        component: xxx, //这个component就是注册的组件
   });

npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: react@18.3.1 npm warn node_modules/react npm warn react@"^18.2.0" from the root project npm warn 46 more (@antv/x6-react-shape, @dnd-kit/modifiers, ...) npm warn npm warn Could not resolve dependency: npm warn peer react@">=16.0.0" from @ant-design/cssinjs@1.24.0 npm warn node_modules/@ant-design/cssinjs npm warn @ant-design/cssinjs@"^1.18.4" from the root project npm warn 8 more (@umijs/plugins, antd, @ant-design/pro-card, ...) npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: react@18.3.1 npm warn node_modules/react npm warn react@"^18.2.0" from the root project npm warn 46 more (@antv/x6-react-shape, @dnd-kit/modifiers, ...) npm warn npm warn Could not resolve dependency: npm warn peer react@"^18.3.1" from react-dom@18.3.1 npm warn node_modules/react-dom npm warn react-dom@"^18.2.0" from the root project npm warn 29 more (@antv/x6-react-shape, @umijs/preset-umi, ...) npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: react@18.3.1 npm warn node_modules/react npm warn react@"^18.2.0" from the root project npm warn 46 more (@antv/x6-react-shape, @dnd-kit/modifiers, ...) npm warn npm warn Could not resolve dependency: npm warn peer react@"^18.3.1" from react-dom@18.3.1 npm warn node_modules/react-dom npm warn react-dom@"^18.2.0" from the root project npm warn 29 more (@antv/x6-react-shape, @umijs/preset-umi, ...) npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: react@18.3.1 npm warn node_modules/react npm warn react@"^18.2.0" from the root project npm warn 46 more (@antv/x6-react-shape, @dnd-kit/modifiers, ...) npm warn npm warn Could not resolve dependency: npm warn peer react@"^18.3.1" from react-dom@18.3.1 npm warn node_modules/react-dom npm warn react-dom@"^18.2.0" from the root project npm warn 29 more (@antv/x6-react-shape, @umijs/preset-umi, ...) npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: react@18.3.1 npm warn node_modules/react npm warn react@"^18.2.0" from the root project npm warn 46 more (@antv/x6-react-shape, @dnd-kit/modifiers, ...) npm warn npm warn Could not resolve dependency: npm warn peer react@"^18.3.1" from react-dom@18.3.1 npm warn node_modules/react-dom npm warn react-dom@"^18.2.0" from the root project npm warn 29 more (@antv/x6-react-shape, @umijs/preset-umi, ...) npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: react@18.3.1 npm warn node_modules/react npm warn react@"^18.2.0" from the root project npm warn 46 more (@antv/x6-react-shape, @dnd-kit/modifiers, ...) npm warn npm warn Could not resolve dependency: npm warn peer react@"^18.3.1" from react-dom@18.3.1 npm warn node_modules/react-dom npm warn react-dom@"^18.2.0" from the root project npm warn 29 more (@antv/x6-react-shape, @umijs/preset-umi, ...) npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: react@18.3.1 npm warn node_modules/react npm warn react@"^18.2.0" from the root project npm warn 46 more (@antv/x6-react-shape, @dnd-kit/modifiers, ...) npm warn npm warn Could not resolve dependency: npm warn peer react@"^18.3.1" from react-dom@18.3.1 npm warn node_modules/react-dom npm warn react-dom@"^18.2.0" from the root project npm warn 29 more (@antv/x6-react-shape, @umijs/preset-umi, ...) npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: react@18.3.1 npm warn node_modules/react npm warn react@"^18.2.0" from the root project npm warn 46 more (@antv/x6-react-shape, @dnd-kit/modifiers, ...) npm warn npm warn Could not resolve dependency: npm warn peer react@"^18.3.1" from react-dom@18.3.1 npm warn node_modules/react-dom npm warn react-dom@"^18.2.0" from the root project npm warn 29 more (@antv/x6-react-shape, @umijs/preset-umi, ...) npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: react@18.3.1 npm warn node_modules/react npm warn react@"^18.2.0" from the root project npm warn 46 more (@antv/x6-react-shape, @dnd-kit/modifiers, ...) npm warn npm warn Could not resolve dependency: npm warn peer react@"^18.3.1" from react-dom@18.3.1 npm warn node_modules/react-dom npm warn react-dom@"^18.2.0" from the root project npm warn 29 more (@antv/x6-react-shape, @umijs/preset-umi, ...) npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: react@18.3.1 npm warn node_modules/react npm warn react@"^18.2.0" from the root project npm warn 46 more (@antv/x6-react-shape, @dnd-kit/modifiers, ...) npm warn npm warn Could not resolve dependency: npm warn peer react@"^18.3.1" from react-dom@18.3.1 npm warn node_modules/react-dom npm warn react-dom@"^18.2.0" from the root project npm warn 29 more (@antv/x6-react-shape, @umijs/preset-umi, ...) npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: react@18.3.1 npm warn node_modules/react npm warn react@"^18.2.0" from the root project npm warn 46 more (@antv/x6-react-shape, @dnd-kit/modifiers, ...) npm warn npm warn Could not resolve dependency: npm warn peer react@"^18.3.1" from react-dom@18.3.1 npm warn node_modules/react-dom npm warn react-dom@"^18.2.0" from the root project npm warn 29 more (@antv/x6-react-shape, @umijs/preset-umi, ...) npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: react@18.3.1 npm warn node_modules/react npm warn react@"^18.2.0" from the root project npm warn 46 more (@antv/x6-react-shape, @dnd-kit/modifiers, ...) npm warn npm warn Could not resolve dependency: npm warn peer react@">=16.0.0" from @ant-design/icons@5.6.1 npm warn node_modules/@ant-design/icons npm warn @ant-design/icons@"^5.2.6" from the root project npm warn 8 more (antd, @ant-design/pro-card, @ant-design/pro-field, ...) npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: react@18.3.1 npm warn node_modules/react npm warn react@"^18.2.0" from the root project npm warn 46 more (@antv/x6-react-shape, @dnd-kit/modifiers, ...) npm warn npm warn Could not resolve dependency: npm warn peer react@">=16.8.0" from @dnd-kit/core@6.3.1 npm warn node_modules/@dnd-kit/core npm warn @dnd-kit/core@"^6.1.0" from the root project npm warn 3 more (@dnd-kit/modifiers, @dnd-kit/sortable, @ant-design/pro-table) npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: react@18.3.1 npm warn node_modules/react npm warn react@"^18.2.0" from the root project npm warn 46 more (@antv/x6-react-shape, @dnd-kit/modifiers, ...) npm warn npm warn Could not resolve dependency: npm warn peer react@">=16.8.0" from @dnd-kit/core@6.3.1 npm warn node_modules/@dnd-kit/core npm warn @dnd-kit/core@"^6.1.0" from the root project npm warn 3 more (@dnd-kit/modifiers, @dnd-kit/sortable, @ant-design/pro-table) npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: react@18.3.1 npm warn node_modules/react npm warn react@"^18.2.0" from the root project npm warn 46 more (@antv/x6-react-shape, @dnd-kit/modifiers, ...) npm warn npm warn Could not resolve dependency: npm warn peer react@">=16.8.0" from @dnd-kit/core@6.3.1 npm warn node_modules/@dnd-kit/core npm warn @dnd-kit/core@"^6.1.0" from the root project npm warn 3 more (@dnd-kit/modifiers, @dnd-kit/sortable, @ant-design/pro-table) npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: react@18.3.1 npm warn node_modules/react npm warn react@"^18.2.0" from the root project npm warn 46 more (@antv/x6-react-shape, @dnd-kit/modifiers, ...) npm warn npm warn Could not resolve dependency: npm warn peer react@">=16.8.0" from @dnd-kit/utilities@3.2.2 npm warn node_modules/@dnd-kit/utilities npm warn @dnd-kit/utilities@"^3.2.2" from the root project npm warn 4 more (@dnd-kit/modifiers, @dnd-kit/sortable, @dnd-kit/core, @ant-design/pro-table) npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: peer react@"15.x || ^16.0.0-0" from the root project npm warn npm warn Could not resolve dependency: npm warn peer react@"15.x || ^16.0.0-0" from the root project npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: react-dom@undefined npm warn node_modules/react-dom npm warn peer react-dom@"15.x || ^16.0.0-0" from the root project npm warn npm warn Could not resolve dependency: npm warn peer react-dom@"15.x || ^16.0.0-0" from the root project npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: react@18.3.1 npm warn node_modules/react npm warn react@"^18.2.0" from the root project npm warn 46 more (@antv/x6-react-shape, @dnd-kit/modifiers, ...) npm warn npm warn Could not resolve dependency: npm warn peer react@">=16.0.0" from @ant-design/cssinjs@1.24.0 npm warn node_modules/@ant-design/cssinjs npm warn @ant-design/cssinjs@"^1.18.4" from the root project npm warn 8 more (@umijs/plugins, antd, @ant-design/pro-card, ...) npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: react@18.3.1 npm warn node_modules/react npm warn react@"^18.2.0" from the root project npm warn 46 more (@antv/x6-react-shape, @dnd-kit/modifiers, ...) npm warn npm warn Could not resolve dependency: npm warn peer react@"^18.3.1" from react-dom@18.3.1 npm warn node_modules/react-dom npm warn react-dom@"^18.2.0" from the root project npm warn 29 more (@antv/x6-react-shape, @umijs/preset-umi, ...) npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: react@18.3.1 npm warn node_modules/react npm warn react@"^18.2.0" from the root project npm warn 46 more (@antv/x6-react-shape, @dnd-kit/modifiers, ...) npm warn npm warn Could not resolve dependency: npm warn peer react@"^18.3.1" from react-dom@18.3.1 npm warn node_modules/react-dom npm warn react-dom@"^18.2.0" from the root project npm warn 29 more (@antv/x6-react-shape, @umijs/preset-umi, ...) npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: react@18.3.1 npm warn node_modules/react npm warn react@"^18.2.0" from the root project npm warn 46 more (@antv/x6-react-shape, @dnd-kit/modifiers, ...) npm warn npm warn Could not resolve dependency: npm warn peer react@"^18.3.1" from react-dom@18.3.1 npm warn node_modules/react-dom npm warn react-dom@"^18.2.0" from the root project npm warn 29 more (@antv/x6-react-shape, @umijs/preset-umi, ...) npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: react@18.3.1 npm warn node_modules/react npm warn react@"^18.2.0" from the root project npm warn 46 more (@antv/x6-react-shape, @dnd-kit/modifiers, ...) npm warn npm warn Could not resolve dependency: npm warn peer react@"^18.3.1" from react-dom@18.3.1 npm warn node_modules/react-dom npm warn react-dom@"^18.2.0" from the root project npm warn 29 more (@antv/x6-react-shape, @umijs/preset-umi, ...) npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: react@18.3.1 npm warn node_modules/react npm warn react@"^18.2.0" from the root project npm warn 46 more (@antv/x6-react-shape, @dnd-kit/modifiers, ...) npm warn npm warn Could not resolve dependency: npm warn peer react@"^18.3.1" from react-dom@18.3.1 npm warn node_modules/react-dom npm warn react-dom@"^18.2.0" from the root project npm warn 29 more (@antv/x6-react-shape, @umijs/preset-umi, ...) npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: react@18.3.1 npm warn node_modules/react npm warn react@"^18.2.0" from the root project npm warn 46 more (@antv/x6-react-shape, @dnd-kit/modifiers, ...) npm warn npm warn Could not resolve dependency: npm warn peer react@"^18.3.1" from react-dom@18.3.1 npm warn node_modules/react-dom npm warn react-dom@"^18.2.0" from the root project npm warn 29 more (@antv/x6-react-shape, @umijs/preset-umi, ...) npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: react@18.3.1 npm warn node_modules/react npm warn react@"^18.2.0" from the root project npm warn 46 more (@antv/x6-react-shape, @dnd-kit/modifiers, ...) npm warn npm warn Could not resolve dependency: npm warn peer react@"^18.3.1" from react-dom@18.3.1 npm warn node_modules/react-dom npm warn react-dom@"^18.2.0" from the root project npm warn 29 more (@antv/x6-react-shape, @umijs/preset-umi, ...) npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: react@18.3.1 npm warn node_modules/react npm warn react@"^18.2.0" from the root project npm warn 46 more (@antv/x6-react-shape, @dnd-kit/modifiers, ...) npm warn npm warn Could not resolve dependency: npm warn peer react@"^18.3.1" from react-dom@18.3.1 npm warn node_modules/react-dom npm warn react-dom@"^18.2.0" from the root project npm warn 29 more (@antv/x6-react-shape, @umijs/preset-umi, ...) npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: react@18.3.1 npm warn node_modules/react npm warn react@"^18.2.0" from the root project npm warn 46 more (@antv/x6-react-shape, @dnd-kit/modifiers, ...) npm warn npm warn Could not resolve dependency: npm warn peer react@"^18.3.1" from react-dom@18.3.1 npm warn node_modules/react-dom npm warn react-dom@"^18.2.0" from the root project npm warn 29 more (@antv/x6-react-shape, @umijs/preset-umi, ...) npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: react@18.3.1 npm warn node_modules/react npm warn react@"^18.2.0" from the root project npm warn 46 more (@antv/x6-react-shape, @dnd-kit/modifiers, ...) npm warn npm warn Could not resolve dependency: npm warn peer react@"^18.3.1" from react-dom@18.3.1 npm warn node_modules/react-dom npm warn react-dom@"^18.2.0" from the root project npm warn 29 more (@antv/x6-react-shape, @umijs/preset-umi, ...) npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: react@18.3.1 npm warn node_modules/react npm warn react@"^18.2.0" from the root project npm warn 46 more (@antv/x6-react-shape, @dnd-kit/modifiers, ...) npm warn npm warn Could not resolve dependency: npm warn peer react@">=16.0.0" from @ant-design/icons@5.6.1 npm warn node_modules/@ant-design/icons npm warn @ant-design/icons@"^5.2.6" from the root project npm warn 8 more (antd, @ant-design/pro-card, @ant-design/pro-field, ...) npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: react@18.3.1 npm warn node_modules/react npm warn react@"^18.2.0" from the root project npm warn 46 more (@antv/x6-react-shape, @dnd-kit/modifiers, ...) npm warn npm warn Could not resolve dependency: npm warn peer react@">=16.8.0" from @dnd-kit/core@6.3.1 npm warn node_modules/@dnd-kit/core npm warn @dnd-kit/core@"^6.1.0" from the root project npm warn 3 more (@dnd-kit/modifiers, @dnd-kit/sortable, @ant-design/pro-table) npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: react@18.3.1 npm warn node_modules/react npm warn react@"^18.2.0" from the root project npm warn 46 more (@antv/x6-react-shape, @dnd-kit/modifiers, ...) npm warn npm warn Could not resolve dependency: npm warn peer react@">=16.8.0" from @dnd-kit/core@6.3.1 npm warn node_modules/@dnd-kit/core npm warn @dnd-kit/core@"^6.1.0" from the root project npm warn 3 more (@dnd-kit/modifiers, @dnd-kit/sortable, @ant-design/pro-table) npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: react@18.3.1 npm warn node_modules/react npm warn react@"^18.2.0" from the root project npm warn 46 more (@antv/x6-react-shape, @dnd-kit/modifiers, ...) npm warn npm warn Could not resolve dependency: npm warn peer react@">=16.8.0" from @dnd-kit/core@6.3.1 npm warn node_modules/@dnd-kit/core npm warn @dnd-kit/core@"^6.1.0" from the root project npm warn 3 more (@dnd-kit/modifiers, @dnd-kit/sortable, @ant-design/pro-table) npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: react@18.3.1 npm warn node_modules/react npm warn react@"^18.2.0" from the root project npm warn 46 more (@antv/x6-react-shape, @dnd-kit/modifiers, ...) npm warn npm warn Could not resolve dependency: npm warn peer react@">=16.8.0" from @dnd-kit/utilities@3.2.2 npm warn node_modules/@dnd-kit/utilities npm warn @dnd-kit/utilities@"^3.2.2" from the root project npm warn 4 more (@dnd-kit/modifiers, @dnd-kit/sortable, @dnd-kit/core, @ant-design/pro-table) npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: peer react@"15.x || ^16.0.0-0" from the root project npm warn npm warn Could not resolve dependency: npm warn peer react@"15.x || ^16.0.0-0" from the root project npm warn ERESOLVE overriding peer dependency npm warn While resolving: dva@2.5.0-beta.2 npm warn Found: react-dom@undefined npm warn node_modules/react-dom npm warn peer react-dom@"15.x || ^16.0.0-0" from the root project npm warn npm warn Could not resolve dependency: npm warn peer react-dom@"15.x || ^16.0.0-0" from the root project ⠇
最新发布
09-26
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值