@yantrix/automata v0.0.1 • 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
>
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
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