Teek API Documentation

In-process publish/subscribe for decoupled app events (:item_selected, :theme_changed) - not Tk events, complementary to Handle#on_click/Handle#on_key. Reach for this only when a direct handle or a shared reactive Var would couple things that should stay decoupled.

Owned by one Session (ui.on/ui.emit/ui.off) - two separate Teek::UI.app instances in the same process never share a bus. Pure Ruby, no Tk/interpreter involved, so it works before realize too.

Inherits: Object

Instance Methods

emit(event, *args, **kwargs)

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

Parameters
  • event Symbol
  • args Array — forwarded to each subscriber
  • kwargs Hash — forwarded to each subscriber

Returns void

initialize

Returns EventBus — a new instance of EventBus

@api private

off(event, block)

Unsubscribe a specific listener.

Parameters
  • event Symbol
  • block Proc — the block #on returned

Returns void

on(event, &block)

Subscribe to a named event.

Parameters
  • event Symbol

Returns Proc — the block, to pass to a later #off

@yield the subscriber, called with whatever #emit was given