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

Node EventListeners don't work when setting a state from component #1017

Open
MrEnte opened this issue Sep 18, 2023 · 0 comments
Open

Node EventListeners don't work when setting a state from component #1017

MrEnte opened this issue Sep 18, 2023 · 0 comments

Comments

@MrEnte
Copy link

MrEnte commented Sep 18, 2023

I am developing a real time collaborative diagram editor. At the moment I am trying to implement the use case when a user sees a node is moved by another user. I thought that the EventListener positionChanged would be a nice fit for this use case. The Code looks like this:

When adding a node i add an EventListener. In there i change the state of serializedModel.

node.registerListener({
    positionChanged: (
        e: BaseEntityEvent<ClassNodeModel>
    ) => {
        window.console.error('positionChanged', e);
        setSerializedModel(model.serialize());
    },
});

serializedModel is just the return value of model.serialize().

Then there is this useEffect:

useEffect(() => {
      window.console.error('useEffect', serializedModel);
      sendJsonMessage({
          serialized_diagram: serializedModel,
      });
      engine.repaintCanvas();
  }, [serializedModel]);

In here a just send a message to my backend to synchronize with the other users.

The Problem right now is that the EventListener only works for a few seconds:
image

But when i do not set a state in the EventListener. So something likes this:

node.registerListener({
    positionChanged: (
        e: BaseEntityEvent<ClassNodeModel>
    ) => {
        window.console.error('positionChanged', e);
    },
});

It works
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant