Skip to content

@yantrix/automata v0.0.1Docs


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>[];
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.


getEventEffects()

ts
getEventEffects: (event) => TAutomataEffect<ModelType, EventType>[];

Returns the effects associated with a specific event.

Parameters

event: EventType

The event for which to retrieve the effects.

Returns

TAutomataEffect<ModelType, EventType>[]

The effects associated with the event.


getEventMatrix()

ts
getEventMatrix: () => Record<EventType, TAutomataEffect<ModelType, EventType>[]>;

Returns the event matrix, which is a record of events and their corresponding effects.

Returns

Record<EventType, TAutomataEffect<ModelType, EventType>[]>

The event matrix.


getEventStack()

ts
getEventStack: () => TAutomataEventStack<EventType, EventMetaType>;

Returns the event stack.

Returns

TAutomataEventStack<EventType, EventMetaType>

The event stack.


getMachines

ts
getMachines: Record<string, IAutomata<any, any, EventType, Record<any, any>, Record<any, any>, Record<EventType, any>>>;

A record of machines, where each machine is an instance of IAutomata.


isRunning()

ts
isRunning: () => boolean;

Checks if the automata slice is running.

Returns

boolean

true if the automata slice is running, false otherwise.


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.


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.