Search code examples
noflo

When do the events emitted by Port get emitted? And what do they mean?


As far as I can tell there are 7 events dispatched by a NoFlo port:

attach, connect, begingroup, data, endgroup, disconnect, detach

To me some of these events sound very similar such as attach + connect, and disconnect + detach. What is the difference?

What does begingroup and endgroup mean?

When do these events get emitted and when are they generally used?

I've seen the documentation at: http://noflojs.org/documentation/components/#portevents

Would my assumption be correct to assume that attach and detach are for handling NoFlo UI cases eg changing the state of the components look?

Another assumption would be that connect gets fired every time before data is sent? Then data gets fired. Then disconnect? Seems a bit odd to me...

I'm completely in the dark when it comes to groups.


Solution

  • attach and detach happen when the NoFlo Network attaches (or removes) a socket to the port. So usually they happen at network start-up time, before IIPs get sent.

    The exception to this is when you're live-editing the graph with a tool like Flowhub. In that situation attach/detach can happen whenever you connect or remove wires.

    Most components don't need to care about the attachment events.

    connect happens before the upstream connection sends data, and disconnect when the upstream connection says that it has sent everything it is intending to send. So in effect they're beginning of transmission and end of transmission events. An upstream component may choose to connect again after a disconnect if it has a new batch of data to send.

    data is the event for actual payload-containing packets.

    begingroup and endgroup are the "bracket IPs" containing metadata about the data being sent. They can be used for creating tree structures with packet data.

    For example, filesystem/ReadFile will send the file contents as a data packet, but the filename is sent via a bracket IP using a begingroup/endgroup packets around the actual file contents.

    The noflo-groups library provides lots of components for utilizing group information for synchronization, routing, etc.