Channel & events
The OmegaChannel is a single broadcast bus: every emission is observed by subscribers (flows via OmegaFlowManager, agents, and any channel.events.subscribe you add).
OmegaChannel
events:Observable<OmegaEvent>— hot stream, no replay; subscribers only see events after they subscribe.emit(event)/emitNamed(name, payload?): publish anOmegaEvent. If the channel wasdispose()d, emits are ignored (optionalonEmitErrorin constructor).emitTyped(typed): wraps a typed payload as the event body (name comes from the typed object).on(name): shortcut —eventsfiltered byevent.name.namespace(ns): returns anOmegaChannelNamespacescoped to that string (see below).dispose(): completes the internal subject; use when tearing down a test or a long-lived subsystem (not usually needed for the root app channel).
OmegaChannelNamespace
Namespaces tag events so subscribers can scope traffic:
emit/emitNamed: setsnamespaceon the forwarded event.events: still multiplexes from the root channel, but only delivers events whosenamespaceisnullor equals this namespace’s name (so you hear global + your slice).
Use namespaces when several features share wire names and you want isolation without separate channel instances.
OmegaEvent
- Fields:
id,name, optionalpayload, optionalnamespace,meta. - Factories:
OmegaEvent.fromName(name, { payload, namespace, … }),fromJson/toJsonfor debugging or persistence.
In handlers, event.payloadAs<T>() narrows payload type when you control the shape.
Design tips
- Stable wire names — centralize string constants (see
AuthWirein the example repo) or useOmegaEventName/OmegaIntentName-style enums from your feature module. - Avoid work in constructors — flows and agents should subscribe in a predictable order (
provideOmegarunsbootstrapandcreateAgentsafter flows are registered). - Errors — channel
emitis synchronous push; uncaught errors in subscribers can break the chain; useonEmitErroron the channel if you need a global safety net.
