Skip to content

Node Type Change

A node's Type can change at runtime: set it, and the node is drawn again with the new type's look and handles. Edges whose handle went away are kept, drawn to the middle of the side the handle was on, and attach again when it comes back.

Input
I can change
Output
bit Blow

Try it

  • Pick input: node 2 loses its target handle and takes the input border colour. The edge from Input is kept, and now ends at the middle of node 2's top side, where the handle was.
  • Pick output: the source handle goes instead, the border takes the output colour, and the edge to Output starts from the middle of node 2's bottom side.
  • Pick default again: both handles are back and both edges attach to them.

How it works

  • Type is a plain property: the list sets _node2.Type, this page re-renders, and the canvas draws node 2 with the built-in renderer for its new type - input has only a source handle, output only a target handle, default both.
  • The node element's class follows the type (bit-blow-node-input, bit-blow-node-output), which is where the coloured borders come from.
  • The canvas measures the nodes again after the render that follows, so the edges re-anchor to the handles that are left with no UpdateNodeInternals call.
  • An edge naming a handle its node no longer has stays in Edges. Its end is drawn to the middle of the node's TargetPosition or SourcePosition side, and no error is raised.
An unhandled error has occurred. Reload 🗙