class

Tryst::UI::EventBus(T)

Inherits Reference < Object

@api private

Internal build-time plumbing for Document (see #subscribe/#notify) - not a public event mechanism. An app's own events are Signal (./signal.cr): one typed object per event name, connected to directly, with a compile-time-checked emit and no Symbol to typo. EventBus predates Signal and was briefly public itself (Session#on/#emit/#off); that surface is gone now that Signal covers what it covered, so nothing outside Document should construct one of these.

In-process publish/subscribe for decoupled events - not Tk events. Pure Crystal, no Tk/interpreter involved.

Generic over the payload type T, unlike ruby-tryst's EventBus (which forwards arbitrary *args/**kwargs to each subscriber - Ruby doesn't care what they are). Crystal needs every subscriber Proc's parameter types fixed at compile time, so each owner picks its own T: Document uses one EventBus(Node | String) internally for its build-time :push/:pop/:append hooks. **kwargs forwarding itself is dropped entirely - nothing in this port's scope emits any, and a Proc can't accept them generically the way a Ruby block can.

Instance methods

emit(event : Symbol) : Nil

Emit a named event carrying no payload at all - the most common kind ("saved", "closed"). Needs to be its own overload rather than falling out of the one below: a splat with a type restriction requires at least one argument in Crystal. Emitting an event nobody listens to is ordinary, so every lookup here is a plain miss rather than a subscriber list conjured into existence and kept forever.

Source
emit(event : Symbol, *args : T) : Nil

Emit a named event to every current subscriber, in subscription order.

Source
off(event : Symbol, listener : Proc(Array(T), Nil)) : Nil

Unsubscribe a specific listener.

Source
on(event : Symbol, &block : Array(T) -> Nil) : Proc(Array(T), Nil)

Subscribe to a named event. Returns the block, to pass to a later #off.

Source