Documentation / @ripl/core / EventBus
Class: EventBus<TEventMap> ​
Defined in: packages/core/src/core/event-bus.ts:99
A typed pub/sub event system with parent-chain bubbling, disposable subscriptions, and self-filtering.
Extends ​
Extended by ​
Type Parameters ​
| Type Parameter | Default type |
|---|---|
TEventMap extends EventMap | EventMap |
Constructors ​
Constructor ​
new EventBus<
TEventMap>():EventBus<TEventMap>
Returns ​
EventBus<TEventMap>
Inherited from ​
Properties ​
| Property | Modifier | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|---|
parent? | public | EventBus<TEventMap> | The parent event bus that emitted events bubble up to, if any. | - | packages/core/src/core/event-bus.ts:107 |
defaultKey | readonly | typeof defaultKey | The key under which resources are retained when no explicit key is provided. | Disposer.defaultKey | packages/core/src/core/disposer.ts:11 |
Accessors ​
$events ​
Get Signature ​
get $events(): keyof
TEventMap[]
Defined in: packages/core/src/core/event-bus.ts:114
The event types this bus can emit. The base returns an empty list; subclasses override it to declare their emittable events (type-checked against their EventMap), so tooling such as the devtools can enumerate them, including events added by custom subclasses.
Returns ​
keyof TEventMap[]
Methods ​
destroy() ​
destroy():
void
Defined in: packages/core/src/core/event-bus.ts:210
Emits a destroyed event, clears all listeners, and disposes retained resources. Idempotent: a second call is a no-op, so a listener registered after teardown is not woken by it.
Returns ​
void
dispose() ​
protecteddispose(key?):void
Defined in: packages/core/src/core/disposer.ts:25
Disposes all resources under the given key, or all resources if no key is provided.
Parameters ​
| Parameter | Type |
|---|---|
key? | PropertyKey |
Returns ​
void
Inherited from ​
emit() ​
Call Signature ​
emit<
TEvent>(event):TEvent
Defined in: packages/core/src/core/event-bus.ts:185
Emits an event, invoking all matching handlers and bubbling to the parent if applicable. Handlers for the event's own type run first, then EVENT_WILDCARD subscriptions.
Type Parameters ​
| Type Parameter | Default type |
|---|---|
TEvent extends Event<undefined> | Event<undefined> |
Parameters ​
| Parameter | Type |
|---|---|
event | TEvent |
Returns ​
TEvent
Call Signature ​
emit<
TEvent>(type,data):Event<TEventMap[TEvent]>
Defined in: packages/core/src/core/event-bus.ts:186
Emits an event, invoking all matching handlers and bubbling to the parent if applicable. Handlers for the event's own type run first, then EVENT_WILDCARD subscriptions.
Type Parameters ​
| Type Parameter |
|---|
TEvent extends string | number | symbol |
Parameters ​
| Parameter | Type |
|---|---|
type | TEvent |
data | TEventMap[TEvent] |
Returns ​
Event<TEventMap[TEvent]>
has() ​
has(
type):boolean
Defined in: packages/core/src/core/event-bus.ts:123
Returns whether there are any listeners registered for the given event type. Wildcard subscriptions (EVENT_WILDCARD) are not listeners for any concrete type, so a bus observed only through the wildcard still reports false here.
Parameters ​
| Parameter | Type |
|---|---|
type | keyof TEventMap |
Returns ​
boolean
off() ​
off<
TEvent>(type,handler):void
Defined in: packages/core/src/core/event-bus.ts:144
Removes a previously registered handler for the given event type.
Type Parameters ​
| Type Parameter |
|---|
TEvent extends string | number | symbol |
Parameters ​
| Parameter | Type |
|---|---|
type | TEvent |
handler | EventHandler<TEventMap[TEvent]> |
Returns ​
void
on() ​
on<
TEvent>(type,handler,options?):Disposable
Defined in: packages/core/src/core/event-bus.ts:131
Subscribes a handler to the given event type and returns a disposable for cleanup. Pass EVENT_WILDCARD to receive every event emitted on the bus regardless of type.
Type Parameters ​
| Type Parameter |
|---|
TEvent extends string | number | symbol |
Parameters ​
| Parameter | Type |
|---|---|
type | TEvent |
handler | EventHandler<TEventMap[TEvent]> |
options? | EventSubscriptionOptions |
Returns ​
once() ​
once<
TEvent>(type,handler,options?):Disposable
Defined in: packages/core/src/core/event-bus.ts:159
Subscribes a handler that is automatically removed after it fires once.
Type Parameters ​
| Type Parameter |
|---|
TEvent extends string | number | symbol |
Parameters ​
| Parameter | Type |
|---|---|
type | TEvent |
handler | EventHandler<TEventMap[TEvent]> |
options? | EventSubscriptionOptions |
Returns ​
retain() ​
protectedretain(value,key?):void
Defined in: packages/core/src/core/disposer.ts:14
Registers a disposable resource under an optional key for later cleanup.
Parameters ​
| Parameter | Type | Default value |
|---|---|---|
value | Disposable | undefined |
key | PropertyKey | Disposer.defaultKey |
Returns ​
void