@ue-too/being / CompositeState
Abstract Class: CompositeState<EventPayloadMapping, Context, ParentStates, ChildStates, EventOutputMapping>
Defined in: hierarchical.ts:106
Composite state that contains a child state machine.
Remarks
A composite state is a state that contains its own internal state machine. When the composite state is active, its child state machine is also active. Events are first handled by the child state machine, and if unhandled, they bubble up to the parent state machine.
Example
type ParentStates = "IDLE" | "ACTIVE";
type ChildStates = "LOADING" | "READY" | "ERROR";
class ActiveState extends CompositeState<Events, Context, ParentStates, ChildStates> {
eventReactions = {
stop: {
action: () => console.log("Stopping..."),
defaultTargetState: "IDLE"
}
};
getChildStateMachine() {
return {
stateMachine: new TemplateStateMachine(...),
defaultChildState: "LOADING",
rememberHistory: true
};
}
}Extends
TemplateState<EventPayloadMapping,Context,ParentStates,EventOutputMapping>
Type Parameters
EventPayloadMapping
EventPayloadMapping = any
Event payload mapping
Context
Context extends BaseContext = BaseContext
Context type
ParentStates
ParentStates extends string = string
Parent state names
ChildStates
ChildStates extends string = string
Child state names
EventOutputMapping
EventOutputMapping extends Partial<Record<keyof EventPayloadMapping, unknown>> = DefaultOutputMapping<EventPayloadMapping>
Event output mapping
Constructors
Constructor
new CompositeState<
EventPayloadMapping,Context,ParentStates,ChildStates,EventOutputMapping>():CompositeState<EventPayloadMapping,Context,ParentStates,ChildStates,EventOutputMapping>
Returns
CompositeState<EventPayloadMapping, Context, ParentStates, ChildStates, EventOutputMapping>
Inherited from
Properties
_childStateMachineConfig
protected_childStateMachineConfig:ChildStateMachineConfig<EventPayloadMapping,Context,ChildStates,EventOutputMapping> |null=null
Defined in: hierarchical.ts:120
_context
protected_context:Context|null=null
Defined in: hierarchical.ts:127
_defer
protected_defer:Defer<Context,EventPayloadMapping,ParentStates,EventOutputMapping> |undefined=undefined
Defined in: interface.ts:854
Inherited from
_delay
protected_delay:Delay<Context,EventPayloadMapping,ParentStates,EventOutputMapping> |undefined=undefined
Defined in: interface.ts:850
Inherited from
_eventGuards
protected_eventGuards:Partial<EventGuards<EventPayloadMapping,States,Context,Guard<Context>>>
Defined in: interface.ts:845
Inherited from
_eventReactions
protected_eventReactions:EventReactions<EventPayloadMapping,Context,States,EventOutputMapping>
Defined in: interface.ts:833
Inherited from
_guards
protected_guards:Guard<Context>
Defined in: interface.ts:844
Inherited from
_historyState
protected_historyState:ChildStates|null=null
Defined in: hierarchical.ts:126
Accessors
delay
Get Signature
get delay():
Delay<Context,EventPayloadMapping,States,EventOutputMapping> |undefined
Defined in: interface.ts:883
Returns
Delay<Context, EventPayloadMapping, States, EventOutputMapping> | undefined
Inherited from
eventGuards
Get Signature
get eventGuards():
Partial<EventGuards<EventPayloadMapping,States,Context,Guard<Context>>>
Defined in: interface.ts:868
Returns
Partial<EventGuards<EventPayloadMapping, States, Context, Guard<Context>>>
Inherited from
eventReactions
Get Signature
get eventReactions():
EventReactions<EventPayloadMapping,Context,States,EventOutputMapping>
Defined in: interface.ts:874
Returns
EventReactions<EventPayloadMapping, Context, States, EventOutputMapping>
Inherited from
guards
Get Signature
get guards():
Guard<Context>
Defined in: interface.ts:864
Returns
Guard<Context>
Inherited from
handlingEvents
Get Signature
get handlingEvents(): keyof
EventPayloadMapping[]
Defined in: interface.ts:858
Returns
keyof EventPayloadMapping[]
Inherited from
Methods
beforeExit()
beforeExit(
context,stateMachine,to):void
Defined in: hierarchical.ts:217
Parameters
context
Context
stateMachine
StateMachine<EventPayloadMapping, Context, ParentStates, EventOutputMapping>
to
"TERMINAL" | ParentStates
Returns
void
Overrides
getChildStateMachine()
abstractprotectedgetChildStateMachine():ChildStateMachineConfig<EventPayloadMapping,Context,ChildStates,EventOutputMapping>
Defined in: hierarchical.ts:133
Returns the configuration for the child state machine. Override this method to provide child state machine setup.
Returns
ChildStateMachineConfig<EventPayloadMapping, Context, ChildStates, EventOutputMapping>
getCurrentChildState()
getCurrentChildState():
ChildStates|null
Defined in: hierarchical.ts:143
Gets the current child state, or null if no child state machine is active.
Returns
ChildStates | null
getStatePath()
getStatePath(
parentState):HierarchicalStatePath<ParentStates,ChildStates>
Defined in: hierarchical.ts:164
Gets the full hierarchical path of the current state.
Parameters
parentState
ParentStates
Returns
HierarchicalStatePath<ParentStates, ChildStates>
handles()
handles<
K>(args,context,stateMachine):EventResult<ParentStates,Kextends keyofEventOutputMapping?EventOutputMapping[K<K>] :void>
Defined in: hierarchical.ts:255
Type Parameters
K
K extends string | number | symbol
Parameters
args
EventArgs<EventPayloadMapping, K>
context
Context
stateMachine
StateMachine<EventPayloadMapping, Context, ParentStates, EventOutputMapping>
Returns
EventResult<ParentStates, K extends keyof EventOutputMapping ? EventOutputMapping[K<K>] : void>
Overrides
uponEnter()
uponEnter(
context,stateMachine,from):void
Defined in: hierarchical.ts:177
Parameters
context
Context
stateMachine
StateMachine<EventPayloadMapping, Context, ParentStates, EventOutputMapping>
from
"INITIAL" | ParentStates
Returns
void