Skip to content

@yantrix/automata v0.5.2 • Docs


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.


resume() ​

ts
resume: () => this;

Resume the event bus.

Returns ​

this

This event bus instance.


setEventValidator() ​

ts
setEventValidator: (eventValidator?) => this;

Sets the event validator function.

Parameters ​

• eventValidator?: TValidator<EventType>

The validator function for the event.

Returns ​

this

The current instance.

Inherited from ​

IAutomataExtendedEventContainer.setEventValidator


subscribe() ​

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

Subscribe 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.


validateEvent ​

ts
validateEvent: TValidator<EventType>;

Validator function for the event.

Inherited from ​

IAutomataExtendedEventContainer.validateEvent