@yantrix/automata v0.6.0 • Docs
Yantrix API / @yantrix/automata / IAutomataSlice
Interface: IAutomataSlice<EventType, EventMetaType, ModelType> ​
Interface representing a slice of an automata.
Extends ​
IAutomataEventContainer<EventType>
Type Parameters ​
• EventType extends TAutomataBaseEventType
The type of events.
• EventMetaType extends { [K in EventType]: any } = Record<EventType, any>
The type of event metadata.
• ModelType extends object = Record<string, any>
The type of the model.
Properties ​
addMachine() ​
ts
addMachine: <StateType, ActionType, ContextType, PayloadType>(machineId, automata) => this;Adds 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.
clearEventStack() ​
ts
clearEventStack: () => this;Clears the event stack.
Returns ​
this
The current instance of IAutomataSlice.
consumeEvent() ​
ts
consumeEvent: () => object;Consumes 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>;dispatchEvent() ​
ts
dispatchEvent: (event) => this;Dispatches an event and triggers its effects.
Parameters ​
• event: TAutomataEventMetaType<EventType, EventMetaType>
The event object to dispatch.
Returns ​
this
The current instance of IAutomataSlice.
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>>
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.
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.
getEventStack() ​
ts
getEventStack: () => TAutomataEventStack<EventType, EventMetaType>;Returns the event stack.
Returns ​
TAutomataEventStack<EventType, EventMetaType>
The event stack.
getMachines() ​
ts
getMachines: () => Readonly<Record<string, IAutomata<any, any, EventType, any, any, EventMetaType>>>;A record of machines, where each machine is an instance of IAutomata.
Returns ​
Readonly<Record<string, IAutomata<any, any, EventType, any, any, EventMetaType>>>
id ​
ts
readonly id: string;Stable Slice identifier used by the Application composition root.
isRunning() ​
ts
isRunning: () => boolean;Checks if the automata slice is running.
Returns ​
boolean
true if the automata slice is running, false otherwise.
onMachinesChanged()? ​
ts
optional onMachinesChanged: (onAdded, onRemoved) => () => void;Observe later membership changes. Mutable Slices notify on addition before enabling the FSM.
Parameters ​
• onAdded
• onRemoved
Returns ​
Function
Returns ​
void
removeMachine() ​
ts
removeMachine: (machineId) => this;Removes a machine from the automata slice.
Parameters ​
• machineId: string
The ID of the machine to remove.
Returns ​
this
The current instance of IAutomataSlice.
restoreCompositeState() ​
ts
restoreCompositeState: (compositeState) => this;Restores 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.
restoreState() ​
ts
restoreState: <StateType, ContextType>(machineId, state) => this;Restores 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.
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 ​
IAutomataEventContainer.setEventValidator
start() ​
ts
start: () => this;Starts the automata slice.
Returns ​
this
The current instance of IAutomataSlice.
stop() ​
ts
stop: (clearStack?) => this;Stops the automata slice.
Parameters ​
• clearStack?: boolean
Indicates whether to clear the event stack.
Returns ​
this
The current instance of IAutomataSlice.
validateEvent ​
ts
validateEvent: TValidator<EventType>;Validator function for the event.