new Mediator<Events>()
Create an independent event bus, optionally with a compile-time event map.
- Returns
- A Mediator instance.
- Runtime
- Browser + Node.js
Application events
A small synchronous Node-compatible event bus for exchanging named application intent without direct module coupling.
import Mediator from 'white-label-mediator';const mediator = new Mediator();Delivery is synchronous and follows EventEmitter listener ordering. Emitting with no subscribers is valid and returns false.
The publisher does not know who listens. Keep callback references so the owner of a subscription can remove it later.
mediator.on('cart:updated', renderCart);
const delivered = mediator.emit('cart:updated', {quantity: 3});Individual components should remove only their own subscriptions. destroy() is for the event bus itself leaving the application and removes every listener owned by that mediator instance.
Typed event maps provide compile-time event/payload checking only; they add no runtime validation.
type Events = {
ready: [name: string];
stopped: [];
};
const mediator = new Mediator<Events>();Router can listen for router:navigate messages. Model can relay namespaced model:<name>:<event> messages to any structurally compatible emitter.
Mediator does not own payload schemas, state changes, rendering, navigation, or lifecycle policy outside its own listeners.
new Mediator<Events>()Create an independent event bus, optionally with a compile-time event map.
initialize()Start the lifecycle for composition/chaining.
destroy()Remove every listener from this mediator instance.
on(name, callback)Subscribe to a named event.
once(name, callback)Subscribe for one delivery.
emit(name, ...payload)Synchronously publish an event.
removeListener(name, callback)Release one owned subscription using the same callback reference.
removeAllListeners(name?)Use the standard EventEmitter broad-cleanup contract.
listenerCount(name)Inspect current listener count for an event.
off(name, callback)Node EventEmitter alias for removeListener().
addListener(name, callback)Node EventEmitter alias for on().
Mediator<Events> narrows event names and payload tuples at compile time.
The runtime remains ordinary EventEmitter behavior; type maps do not validate payloads at runtime.
Treat event payloads according to their original trust boundary; Mediator does not sanitize or validate them.
Mediator moves named messages. It does not own application state, rendering, routing, networking, persistence, or business behavior.