Skip to content

Handle Rules

Rules can live on the handle they belong to instead of in one canvas-wide predicate: a BlowHandle can carry its own IsValidConnection and OnConnect, a DataType and a MaxConnections, and can refuse to start or to accept connections at all. Use it when each port of a node template has rules of its own.

No connection made yet.
Producer
number
text
Adder
rule: numbers only
0/1
Formatter
DataType: text
bit Blow

Try it

  • Drag from Producer's number output: the Adder's input turns green and the Formatter's red. From the text output it is the other way round. Release on the green one to connect; the line beside the toolbar says which input announced the arrival.
  • Release on a red input: nothing connects, and the line says why - the Adder refuses by its rule, the Formatter by its data type.
  • Drag backwards from the Adder's input to the text output: refused too, because the rule of the handle a drag starts at gets a say as well as the one it ends on.
  • With Adder takes one wire ticked, connect the number output to the Adder, then try again: the Adder's input is full, shows 1/1 - full, and no longer starts or accepts connections until you delete the edge (select it, then Delete) or untick the box.
  • Change Formatter's input: with IsConnectableStart = false pressing it starts nothing, but a drag still ends there; with IsConnectableEnd = false nothing can be dropped on it, though a drag can still start from it; IsConnectable = false does neither. Reset clears the edges.

How it works

  • IsValidConnection on a BlowHandle is a Func<BlowConnection, bool> like the canvas's. The rules of both handles a connection would join are asked, together with the canvas's, and a refusal is RejectedByRule.
  • DataType declares what a handle carries; incompatible types are refused as IncompatibleTypes, and the type is rendered as data-port-type, which this page's stylesheet colours by. It overrides the DataType of a port declared in BlowNode.Ports - see Typed Ports for the model side.
  • MaxConnections (null for no limit) caps a handle's edges. At the limit the handle neither starts nor accepts connections and is not drawn as connectable; a drop is TargetFull or SourceFull. The canvas's CountConnections and IsHandleAtLimit give the Adder's 1/1 - full.
  • IsConnectableStart and IsConnectableEnd (both true by default) switch off starting a connection at the handle, or ending one on it; IsConnectable switches off both. A drop on a handle that takes none is refused as NotConnectable.
  • OnConnect on a handle is raised when the user makes a new connection at it - by dragging, by clicks or from the keyboard, though not when an existing edge is reconnected to it. OnConnectEnd on the canvas reports the refusals, with their Rejection.
An unhandled error has occurred. Reload 🗙