Skip to content

@yantrix/automata v0.0.1Docs


Yantrix API / @yantrix/automata / IAutomataEventAdapter

Interface: IAutomataEventAdapter<StateType, ActionType, EventType, ContextType, PayloadType, EventMetaType>

Interface for an Automata event adapter.

Extends

  • IAutomataValidatorContainer<StateType, ActionType, EventType>

Type Parameters

StateType extends TAutomataBaseStateType

The type of the state.

ActionType extends TAutomataBaseActionType

The type of the action.

EventType extends TAutomataBaseEventType

The type of the event.

ContextType extends { [K in StateType]: any } = Record<StateType, any>

The type of the context.

PayloadType extends { [K in ActionType]: any } = Record<ActionType, any>

The type of the payload.

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

The type of the event metadata.

Properties

addEventEmitter()

ts
addEventEmitter: <T>(on, emitter) => null | TSubscriptionCancelFunction;

Adds an event emitter for the specified state type.

Type Parameters

T extends number

Parameters

on: T

The state type to listen for.

emitter: TAutomataEventEmitter<EventType, T, EventMetaType, ContextType>

The event emitter function.

Returns

null | TSubscriptionCancelFunction

A cancel function to remove the event emitter, or null if the state type is invalid.


addEventListener()

ts
addEventListener: <T>(type, handler) => null | TSubscriptionCancelFunction;

Adds an event listener for the specified event type.

Type Parameters

T extends number

Parameters

type: T

The type of the event.

handler: TAutomataEventHandler<T, ActionType, EventMetaType, PayloadType>

The event handler function.

Returns

null | TSubscriptionCancelFunction

A cancel function to remove the event listener, or null if the event type is invalid.


getObservedEvents()

ts
getObservedEvents: () => EventType[];

Returns an array of the observed event types.

Returns

EventType[]

An array of the observed event types.


getObservedStates()

ts
getObservedStates: () => StateType[];

Returns an array of the observed state types.

Returns

StateType[]

An array of the observed state types.


handleEvent()

ts
handleEvent: <T>(event) => TAutomataActionPayload<ActionType, PayloadType>[];

Handles the specified event and returns the results of the event handlers.

Type Parameters

T extends number

Parameters

event: TAutomataEventMetaType<T, EventMetaType>

The event to handle.

Returns

TAutomataActionPayload<ActionType, PayloadType>[]

An array of the results of the event handlers.


handleTransition()

ts
handleTransition: <T>(newState) => TAutomataEventMetaType<EventType, EventMetaType>[];

Handles the transition to the specified new state and returns the results of the event emitters.

Type Parameters

T extends number

Parameters

newState: TAutomataStateContext<T, ContextType>

The new state to transition to.

Returns

TAutomataEventMetaType<EventType, EventMetaType>[]

An array of the results of the event emitters.


removeAllEmitters()

ts
removeAllEmitters: <T>(type) => this;

Removes all event emitters for the specified state type.

Type Parameters

T extends number

Parameters

type: null | T

The type of the state, or null to remove all event emitters.

Returns

this

The event adapter instance.


removeAllListeners()

ts
removeAllListeners: <T>(type) => this;

Removes all event listeners for the specified event type.

Type Parameters

T extends number

Parameters

type: null | T

The type of the event, or null to remove all event listeners.

Returns

this

The event adapter instance.