Skip to content

Confirm Connection

OnBeforeConnect has the last word on a connection the user has just made - an asynchronous check, such as asking a server whether they may. The edge is added, or a reconnected edge rewired, only if it answers yes, and OnConnectEnd then reports the outcome.

Server idle.
Draft
Review
Archive
Publish
bit Blow

Try it

  • Drag from Draft's handle to Archive's and let go: the line disappears at once, the toolbar says it is waiting, and after the Latency the server's answer arrives and the edge appears. The log under the canvas shows each step.
  • Set Server to refuses everything and connect again: no edge, and OnConnectEnd reports IsValid = false with Rejection = RejectedByRule.
  • Click the Draft-to-Review edge to select it, then drag the dot at its Review end onto Archive or Publish: the server is asked about the rewired edge too, and a refusal leaves it where it was (OnReconnectEnd says Rewired = false).
  • Set Server to refuses edges into Publish and drag to Publish: its handle still turns green, because the server's rule cannot be seen until you let go. Tick Refuse edges into Publish while dragging: the same rule, now synchronous, turns the handle red, and a drop there is refused without asking the server.
  • Slide Latency to 3000 ms and draw the same connection twice before the first answer: both were allowed when you let go, but when the second answer arrives the edge exists, so the canvas checks again and refuses it as a Duplicate. Reset restores the graph and clears the log.

How it works

  • OnBeforeConnect is a Func<BlowConnection, Task<bool>>, called when the user lets go on a handle that accepts the connection - after every synchronous rule has passed. Returning true adds the edge; false abandons it. This page stands in for a server with Task.Delay, and calls StateHasChanged itself, since a Func is not an EventCallback.
  • It confirms a reconnected edge the same way: the BlowConnection it receives is the edge's new wiring, and the edge is rewired only on true. Should the end that stays put move while it waits - the other end of the same edge reconnected and confirmed first - the answer - yes or no - covered a wiring that would no longer be made, so it is asked again about the wiring as it is now. A wiring it has already answered about is not asked about twice, and one that keeps changing is dropped after three answers, with Rejection = Unsettled.
  • The line goes when the user lets go, not when the answer comes, so the next connection can be started while one is waiting. The graph may change meanwhile, so when the answer is yes the connection is checked against every rule again and dropped if it no longer passes.
  • OnConnectEnd arrives after the answer: IsValid when the edge was made, otherwise a Rejection - RejectedByRule for a no, or the reason the second check failed. OnReconnectEnd follows with Rewired. An exception thrown by the confirmation reaches the renderer like one from an event handler.
  • Rules a connection must pass while it is dragged belong in IsValidConnection: it is synchronous because it runs for every handle on every frame of the drag, and its verdict colours the handles. OnBeforeConnect is for what only a slower authority can answer - a permission, a quota, a lock held by someone else.
An unhandled error has occurred. Reload 🗙