Skip to content

@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 ​

Properties ​

id ​

ts
readonly id: string;

Stable Slice identifier used by the Application composition root.

Implementation of ​

IAutomataSlice.id

Accessors ​

validateEvent ​

ts
get validateEvent(): TValidator<EventType>

Validator function for the event.

Returns ​

TValidator<EventType>

Validator function for the event.

Implementation of ​

IAutomataSlice.validateEvent

Methods ​

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.

Implementation of ​

IAutomataSlice.addMachine


clearEventStack() ​

ts
clearEventStack(): this

Clears the event stack.

Returns ​

this

The current instance of IAutomataSlice.

Implementation of ​

IAutomataSlice.clearEventStack


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>;

Implementation of ​

IAutomataSlice.consumeEvent


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.

Implementation of ​

IAutomataSlice.dispatchEvent


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 ​

IAutomataSlice.getEventMatrix


getEventStack() ​

ts
getEventStack(): TAutomataEventStack<EventType, EventMetaType>

Returns the event stack.

Returns ​

TAutomataEventStack<EventType, EventMetaType>

The event stack.

Implementation of ​

IAutomataSlice.getEventStack


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 ​

IAutomataSlice.getMachines


isRunning() ​

ts
isRunning(): boolean

Checks if the automata slice is running.

Returns ​

boolean

true if the automata slice is running, false otherwise.

Implementation of ​

IAutomataSlice.isRunning


onMachinesChanged() ​

ts
onMachinesChanged(onAdded, onRemoved): () => void

Observe 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): 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.

Implementation of ​

IAutomataSlice.removeMachine


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.

Implementation of ​

IAutomataSlice.restoreCompositeState


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.

Implementation of ​

IAutomataSlice.restoreState


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.

Implementation of ​

IAutomataSlice.setEventValidator


start() ​

ts
start(): this

Starts the automata slice.

Returns ​

this

The current instance of IAutomataSlice.

Implementation of ​

IAutomataSlice.start


stop() ​

ts
stop(clearStack): this

Stops the automata slice.

Parameters ​

• clearStack: boolean = false

Indicates whether to clear the event stack.

Returns ​

this

The current instance of IAutomataSlice.

Implementation of ​

IAutomataSlice.stop