@yantrix/automata v0.6.0 • Docs
Yantrix API / @yantrix/automata / IAutomata
Interface: IAutomata<StateType, ActionType, EventType, ContextType, PayloadType, EventMetaType> ​
Interface for Automata, a state machine.
Extends ​
TAutomataStateContext<StateType,ContextType>.IAutomataValidatorContainer<StateType,ActionType,EventType>.IBaseClass
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 ​
collapseActionQueue() ​
ts
collapseActionQueue: () => object;Consume all Actions in the Queue and return the resulting State Works even when Paused When Disabled, consumed Actions don't change the internal State Returns the final result of all consumed Actions
Returns ​
object
actions ​
ts
actions: null | TAutomataQueue<ActionType, PayloadType>;newState ​
ts
newState: TAutomataStateContext<StateType, ContextType>;consumeAction() ​
ts
consumeAction: (count) => object;Pop at most [count] Actions from the Queue and Consume them Works even when Paused When Disabled, consumed Actions don't change the internal State Returns the final result of all consumed Actions
Parameters ​
• count: number
Number of Actions to consume, defaults to 1
Returns ​
object
action ​
ts
action: null | TAutomataActionPayload<ActionType, PayloadType>;newState ​
ts
newState: TAutomataStateContext<StateType, ContextType>;dispatch ​
ts
dispatch: TAutomataDispatch<StateType, ActionType, ContextType, PayloadType>;Consume Action and return the new State and its context. The Queue is Collapsed beforehand, if not Disabled When Paused, puts an Action into the Queue instead When Disabled, doesn't change the internal State Returns the final result of all Actions, including the Queue
enable() ​
ts
enable: () => this;When the Instance is Disabled, Consuming Actions doesn't change the internal state
Returns ​
this
getContext() ​
ts
getContext: <K>() => TAutomataStateContext<K, ContextType>;Returns internal State and Context of the Instance
Type Parameters ​
• K extends number = StateType
Returns ​
TAutomataStateContext<K, ContextType>
getReducer() ​
ts
getReducer: () => null | TAutomataReducer<StateType, ActionType, ContextType, PayloadType>;Return current Reducer function
Returns ​
null | TAutomataReducer<StateType, ActionType, ContextType, PayloadType>
init() ​
ts
init: (params) => this;Reset the Instance and provide a Reducer, new State and optionally Validators
Parameters ​
• params: TAutomataParams<StateType, ActionType, EventType, ContextType, PayloadType, EventMetaType>
Returns ​
this
isPaused() ​
ts
isPaused: () => boolean;When the Instance is Paused, dispatched Actions aren't Consumed, but put into the Queue instead
Returns ​
boolean
onEmittedEvents()? ​
ts
optional onEmittedEvents: (listener) => () => void;Subscribe to events produced by committed transitions, including queued actions when consumed.
Parameters ​
• listener
Returns ​
Function
Returns ​
void
pause() ​
ts
pause: () => this;Pause the automata.
Returns ​
this
The updated automata instance.
resume() ​
ts
resume: () => this;Resuming will Collapse the Queue, unless the Instance is Disabled
Returns ​
this
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
setContext() ​
ts
setContext: (context) => this;Restores the current State and Context snapshot.
Parameters ​
• context: TAutomataStateContext<StateType, ContextType>
Returns ​
this
setEventAdapter() ​
ts
setEventAdapter: (adapter) => this;Sets the event adapter for handling and mapping events.
Parameters ​
• adapter: null | IAutomataEventAdapter<StateType, ActionType, EventType, ContextType, PayloadType, EventMetaType>
The event adapter to be set, or null to remove the current adapter.
Returns ​
this
Returns the current instance for method chaining.
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.