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

Event with namespace specified not triggering #3237

Closed
Ciappone opened this issue Apr 12, 2024 · 1 comment
Closed

Event with namespace specified not triggering #3237

Ciappone opened this issue Apr 12, 2024 · 1 comment
Assignees
Labels
bug A bug in the code of Cytoscape.js
Milestone

Comments

@Ciappone
Copy link

  • Cytoscape.js version : 3.20.0 ( tested with 3.28.1 too )
  • Browser/Node.js & version : Google Chrome v. 123.0.6312.122 / Mozilla Firefox v. 124.0.2

Current (buggy) behaviour

If I assign an event ( "select" in this case ) with a namespace specified the event doesn't trigger or the Event object's property "namespace" is null

Desired behaviour

The event should trigger normally and have the Event object's property "namespace" valorized with the one assigned

Minimum steps to reproduce

I tried assigning the event in two ways:

  • first: in this case the event doesn't trigger
 cy.on("select.test","node",(evt) => {
    document.getElementById("log").innerHTML += "Node selected with namespace: " + evt.namespace+"<br />";
  });
  • second: in this case the event trigger but the namespace is null
 cy.on("select","node",(evt) => {
    document.getElementById("log").innerHTML += "Node selected with namespace: " + evt.namespace+"<br />";
  },'test');

I'll add a JSBin where you can see the problem
JSBin

@Ciappone Ciappone added the bug A bug in the code of Cytoscape.js label Apr 12, 2024
@mikekucera mikekucera self-assigned this Apr 17, 2024
@mikekucera mikekucera added this to the 3.30.0 milestone May 16, 2024
@mikekucera mikekucera assigned jingjingbic and d2fong and unassigned mikekucera May 16, 2024
@mikekucera
Copy link
Contributor

mikekucera commented May 29, 2024

I'm not 100% sure what the utility of the 'namespace' field is, but I don't think the behaviour of the JSBin is wrong.

Both listeners and events can provide a namespace. When the listener specifies a namespace it will only run if the event has the same namespace.

In the sample JSBin the event that fires when selecting a node is just "select", which does not match "select.test", that's why the handler doesn't run. It appears to be intended to work this way.

You can see here, if the listener has a namespace it must match the event's namespace. The "select" event doesn't have a namespace so it doesn't match "select.test":
https://github.com/cytoscape/cytoscape.js/blob/unstable/src/emitter.js#L203

Also, cy.on(...) doesn't take a 4th parameter.
https://js.cytoscape.org/#cy.on

I don't know of any examples of built-in cy.js events that have namespaces. They may exist but I'm not aware of any.

You can manually fire an event with a namespace by calling cy.emit("foo.namespace"), which appears to work as expected.

In other words I don't think this is a bug.

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug in the code of Cytoscape.js
Projects
None yet
Development

No branches or pull requests

4 participants