Skip to content
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

调用自定义节点的 updateData 方法没有更新节点 #1176

Closed
javanoclaw opened this issue Jul 16, 2021 · 14 comments
Closed

调用自定义节点的 updateData 方法没有更新节点 #1176

javanoclaw opened this issue Jul 16, 2021 · 14 comments
Labels
stale Issue that may be closed soon due to the original author not responding any more. type: bug 缺陷 Defects and unexpected behaviors

Comments

@javanoclaw
Copy link

javanoclaw commented Jul 16, 2021

Expected Behavior

使用自定义节点且调用 updateData 方法应该更新节点

Current Behavior

使用自定义节点且调用 updateData 方法没有更新节点

Steps To Reproduce

https://codesandbox.io/s/jovial-hypatia-1lc2i?file=/src/app.tsx:319-328

Additional Context

定义如下节点:

import { Graph, Node, ObjectExt } from "@antv/x6";
class CustomNode extends Node {}

CustomNode.config({
  width: 100,
  height: 100,
  markup: [
    {
      tagName: "rect",
      selector: "body"
    },
    {
      tagName: "text",
      selector: "title"
    }
  ],
  propHooks(metadata) {
    const { data, ...others } = metadata;
    ObjectExt.setByPath(others, "attrs/title/text", data?.name);
    return { data, ...others };
  }
});
Graph.registerNode("custom-node", CustomNode);

通过如下方式更新节点数据:

graph.getNodes.forEach((node)=>{
  node.updateData({name:Math.random()});
});

Your Environment

codesandbox.io

@javanoclaw javanoclaw added the type: bug 缺陷 Defects and unexpected behaviors label Jul 16, 2021
@x6-bot
Copy link
Contributor

x6-bot bot commented Jul 16, 2021

👋 @javanoclaw

Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it.

To help make it easier for us to investigate your issue, please follow the contributing guidelines.

We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

@javanoclaw javanoclaw changed the title 使用自定义节点调用 updateData 方法没有更新节点 调用自定义节点的 updateData 方法没有更新节点 Jul 16, 2021
@x6-bot
Copy link
Contributor

x6-bot bot commented Aug 6, 2021

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not-stale" to keep this issue open!

As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the AntV community! 💪💯

@x6-bot x6-bot bot added the stale Issue that may be closed soon due to the original author not responding any more. label Aug 6, 2021
@x6-bot
Copy link
Contributor

x6-bot bot commented Sep 16, 2021

Hey again!

It’s been 60 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it. Please keep in mind that I’m only a robot 🤖, so if I’ve closed this issue in error, I’m HUMAN_EMOTION_SORRY. Please feel free to comment on this issue or create a new one if you need anything else.

As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out contribute for more information about opening PRs, triaging issues, and contributing!

Thanks again for being part of the AntV community! 💪💯

@x6-bot x6-bot bot closed this as completed Sep 16, 2021
@EmiyaYang
Copy link

我也遇到了,这个没人关注吗? @NewByVector

@zzjjbbaa
Copy link

me too 。。。。。

@NewByVector
Copy link
Contributor

@EmiyaYang @zzjjbbaa 有复现的 demo 链接吗,可以新建一个 issue。

@quicklyfast
Copy link

//propHooks从名字看处理prop的,需要将node.updateData({name:Math.random()}); 写成
node.setProp({name:Math.random(), id: node.id});  # 之所以要传递id属性,是因为x6存在一个bug

具体处理流程看/packages/x6/src/model/cell.ts

image

@psc0606
Copy link

psc0606 commented Oct 12, 2022

这个问题竟然还没人修复,真奇葩

@alienzhangyw
Copy link

alienzhangyw commented Oct 28, 2022

propHooks的metadata里解构出来的data老是undefined,没法通过这种方式改变属性
image
即使在Node.config里对data进行了初始化赋值,依然获取不到。还有节点clone之后data也会丢失。

@superchenwb
Copy link

一年半了,这个bug依然存在

@NewByVector
Copy link
Contributor

更新 data 并不会调用 propHooks,因为 propHooks 是为了首次渲染而设计的。这里更合理的方式是监听 data:change事件,然后在事件回调中去修改相应的属性。

@notbucai
Copy link

怎么还有这个问题

@notbucai
Copy link

change:data 也没用

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Issue that may be closed soon due to the original author not responding any more. type: bug 缺陷 Defects and unexpected behaviors
Projects
None yet
Development

No branches or pull requests

9 participants