Skip to content

@yantrix/automata v0.0.2Docs


Yantrix API / @yantrix/automata / IAutomataEventAdapter

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

Interface for an Automata event adapter.

Extends

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.


setActionValidator()

ts
setActionValidator: (actionValidator?) => this;

Sets the action validator function.

Parameters

actionValidator?: null | TValidator<ActionType>

The validator function for the action.

Returns

this

The current instance.

Inherited from

IAutomataValidatorContainer.setActionValidator


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

IAutomataValidatorContainer.setEventValidator


setStateValidator()

ts
setStateValidator: (stateValidator?) => this;

Sets the state validator function.

Parameters

stateValidator?: TValidator<StateType>

The validator function for the state.

Returns

this

The current instance.

Inherited from

IAutomataValidatorContainer.setStateValidator


validateAction

ts
validateAction: TValidator<ActionType>;

Validator function for the action.

Inherited from

IAutomataValidatorContainer.validateAction


validateEvent

ts
validateEvent: TValidator<EventType>;

Validator function for the event.

Inherited from

IAutomataValidatorContainer.validateEvent


validateState

ts
validateState: TValidator<StateType>;

Validator function for the state.

Inherited from

IAutomataValidatorContainer.validateState