Skip to content

Finding connected nodes #340

@ianchanning

Description

@ianchanning

Traversing the diagram seems quite complex.

As far as I can tell any two nodes are connected via:

Screenshot from 2019-04-30 16-22-51

(child) Node 1 -- (source) Out port -- link -- (target) In port -- (parent) Node 2

This is the code that I have for finding the child nodes connected via a port to a parent node:

/**
 * Find children of a node
 * @param   {Node}    node     Parent node
 * @param   {string}  portName Port connecting to children e.g. 'In'
 * @returns {[Node]}           List of Nodes
 */
const children = (node, portName) => { 
  const links = Object.values(node.getPort(portName).getLinks());
  return links.map(link => link.getSourcePort().getNode());
};

Links and Ports are both objects so to iterate over them you have to do something like Object.values or Object.entries each time

Is there some other/neater way of doing this?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions