projectstorm / react-diagrams

a super simple, no-nonsense diagramming library written in react that just works
https://projectstorm.cloud/react-diagrams
MIT License
8.6k stars 1.17k forks source link

Model breaks if several ports have same name #735

Closed madupuis closed 3 years ago

madupuis commented 3 years ago

In PortModel :

addPort(port: PortModel): PortModel {
    port.setParent(this);
    this.ports[port.getName()] = port;
    return port;
}

==> This will cause model to break if several nodes have the same name. This can happen if the node name can be set by the user. All maps shoud be indexed on ID and not name.

renato-bohler commented 3 years ago

Pull request https://github.com/projectstorm/react-diagrams/pull/725 has a little bit of discussion about this.

If you need port name to not be unique, maybe you should just generate an UUID for the name and create a custom property on your Port to use as the name.

dylanvorster commented 3 years ago

As @renato-bohler has stated, I probably should have called that id instead of name since the port names are supposed to be unique. The important thing is that name in this case is an internal library thing, it doesnt have to be the display name of the port. If a custom display name for a port is required, extend the port model and add the additional fields you require.