Skip to content

@yantrix/automata v0.0.1Docs


Yantrix API / @yantrix/automata / IAutomataEventBus

Interface: IAutomataEventBus<EventType, EventMetaType>

Interface for an event bus that supports subscribing and dispatching events.

Extends

Type Parameters

EventType extends TAutomataBaseEventType

The type of events that can be dispatched.

EventMetaType extends { [K in EventType]: any } = Record<EventType, any>

The type of metadata associated with each event.

Properties

clearEventStack()

ts
clearEventStack: () => this;

Clear the event stack.

Returns

this

This event bus instance.


dispatch()

ts
dispatch: (...events) => this;

Dispatch one or more events.

Parameters

• ...events: TAutomataEventStack<EventType, EventMetaType>

The events to dispatch.

Returns

this

This event bus instance.


getEventStack()

ts
getEventStack: () => TAutomataEventStack<EventType, EventMetaType>;

Get the current event stack.

Returns

TAutomataEventStack<EventType, EventMetaType>

The current event stack.


isRunning()

ts
isRunning: () => boolean;

Check if the event bus is running.

Returns

boolean

True if the event bus is running, false otherwise.


pause()

ts
pause: () => this;

Pause the event bus.

Returns

this

This event bus instance.


processEvents()

ts
processEvents: () => TAutomataEventStack<EventType, EventMetaType>;

Process the events in the event stack.

Returns

TAutomataEventStack<EventType, EventMetaType>

The processed event stack.


resume()

ts
resume: () => this;

Resume the event bus.

Returns

this

This event bus instance.


subscribe()

ts
subscribe: (event, callback) => this;

Subscribe n to an event.

Parameters

event: EventType

The event to subscribe to.

callback: TEventBusHandler<EventType, EventMetaType>

The callback function to call when the event is dispatched.

Returns

this

This event bus instance.


unsubscribe()

ts
unsubscribe: (event, callback) => this;

Unsubscribe from an event.

Parameters

event: EventType

The event to unsubscribe from.

callback: null | TEventBusHandler<EventType, EventMetaType>

The callback function to unsubscribe.

Returns

this

This event bus instance.