@yantrix/automata v0.6.0 • Docs
Yantrix API / @yantrix/automata / AutomataSlice
Class: AutomataSlice<ModelType, EventType, EventMetaType> ​
Independent unit of Yantrix business logic: FSMs plus an Effect Matrix.
Type Parameters ​
• ModelType extends object
• EventType extends TAutomataBaseEventType = TAutomataBaseEventType
• EventMetaType extends { [K in EventType]: any } = Record<EventType, any>
Implements ​
IAutomataSlice<EventType,EventMetaType,ModelType>
Properties ​
id ​
ts
readonly id: string;Stable Slice identifier used by the Application composition root.
Implementation of ​
Accessors ​
validateEvent ​
ts
get validateEvent(): TValidator<EventType>Validator function for the event.
Returns ​
TValidator<EventType>
Validator function for the event.
Implementation of ​
Methods ​
addMachine() ​
ts
addMachine<StateType, ActionType, ContextType, PayloadType>(machineId, automata): thisAdds a machine to the automata slice.
Type Parameters ​
• StateType extends number
• ActionType extends number
• ContextType extends { [K in number]: any } = Record<StateType, any>
• PayloadType extends { [K in number]: any } = Record<ActionType, any>
Parameters ​
• machineId: string
The ID of the machine.
• automata: IAutomata<StateType, ActionType, EventType, ContextType, PayloadType, EventMetaType>
The instance of IAutomata to add.
Returns ​
this
The current instance of IAutomataSlice.
Implementation of ​
clearEventStack() ​
ts
clearEventStack(): thisClears the event stack.
Returns ​
this
The current instance of IAutomataSlice.
Implementation of ​
IAutomataSlice.clearEventStack
consumeEvent() ​
ts
consumeEvent(): objectConsumes the event stack and returns the events and their effects.
Returns ​
object
An object containing the events and their effects.
effects ​
ts
effects: TAutomataEffect<ModelType, EventType, EventMetaType>[];events ​
ts
events: TAutomataEventStack<EventType, EventMetaType>;Implementation of ​
dispatchEvent() ​
ts
dispatchEvent(event): thisDispatches an event and triggers its effects.
Parameters ​
• event: TAutomataEventMetaType<EventType, EventMetaType>
The event object to dispatch.
Returns ​
this
The current instance of IAutomataSlice.
Implementation of ​
getCompositeState() ​
ts
getCompositeState(): Record<string, TAutomataStateContext<any, any>>A record of composite states, where each composite state is an instance of TAutomataStateContext.
Returns ​
Record<string, TAutomataStateContext<any, any>>
Implementation of ​
IAutomataSlice.getCompositeState
getEventEffects() ​
ts
getEventEffects(event): TAutomataEffect<ModelType, EventType, EventMetaType>[]Returns the effects associated with a specific event.
Parameters ​
• event: EventType
The event for which to retrieve the effects.
Returns ​
TAutomataEffect<ModelType, EventType, EventMetaType>[]
The effects associated with the event.
Implementation of ​
IAutomataSlice.getEventEffects
getEventMatrix() ​
ts
getEventMatrix(): TEffectMatrix<ModelType, EventType, EventMetaType>Returns the event matrix, which is a record of events and their corresponding effects.
Returns ​
TEffectMatrix<ModelType, EventType, EventMetaType>
The event matrix.
Implementation of ​
getEventStack() ​
ts
getEventStack(): TAutomataEventStack<EventType, EventMetaType>Returns the event stack.
Returns ​
TAutomataEventStack<EventType, EventMetaType>
The event stack.
Implementation of ​
getMachines() ​
ts
getMachines(): Readonly<Record<string, TSliceMachine<EventType, EventMetaType>>>A record of machines, where each machine is an instance of IAutomata.
Returns ​
Readonly<Record<string, TSliceMachine<EventType, EventMetaType>>>
Implementation of ​
isRunning() ​
ts
isRunning(): booleanChecks if the automata slice is running.
Returns ​
boolean
true if the automata slice is running, false otherwise.
Implementation of ​
onMachinesChanged() ​
ts
onMachinesChanged(onAdded, onRemoved): () => voidObserve later membership changes. Mutable Slices notify on addition before enabling the FSM.
Parameters ​
• onAdded
• onRemoved
Returns ​
Function
Returns ​
void
Implementation of ​
IAutomataSlice.onMachinesChanged
removeMachine() ​
ts
removeMachine(machineId): thisRemoves a machine from the automata slice.
Parameters ​
• machineId: string
The ID of the machine to remove.
Returns ​
this
The current instance of IAutomataSlice.
Implementation of ​
restoreCompositeState() ​
ts
restoreCompositeState(compositeState): thisRestores composite states for all machines.
Parameters ​
• compositeState: Record<string, TAutomataStateContext<any, any>>
The record of composite states to restore.
Returns ​
this
The current instance of IAutomataSlice.
Implementation of ​
IAutomataSlice.restoreCompositeState
restoreState() ​
ts
restoreState<StateType, ContextType>(machineId, state): thisRestores a state for a specific machine.
Type Parameters ​
• StateType extends number
• ContextType extends { [K in number]: any } = Record<StateType, any>
Parameters ​
• machineId: string
The ID of the machine.
• state: TAutomataStateContext<StateType, ContextType>
The state object to restore.
Returns ​
this
The current instance of IAutomataSlice.
Implementation of ​
setEventValidator() ​
ts
setEventValidator(eventValidator?): thisSets the event validator function.
Parameters ​
• eventValidator?: TValidator<EventType>
The validator function for the event.
Returns ​
this
The current instance.
Implementation of ​
IAutomataSlice.setEventValidator
start() ​
ts
start(): thisStarts the automata slice.
Returns ​
this
The current instance of IAutomataSlice.
Implementation of ​
stop() ​
ts
stop(clearStack): thisStops the automata slice.
Parameters ​
• clearStack: boolean = false
Indicates whether to clear the event stack.
Returns ​
this
The current instance of IAutomataSlice.