@ue-too/being / index / StateDefinition
インターフェイス: StateDefinition<Context, EventPayloadMapping, StateNames, EventOutputMapping>
Definition of a single state in the state machine.
例
{
name: "PAYING",
guards: {
hasEnoughBalance: (context) => context.balance >= context.itemPrice,
hasInsufficientBalance: (context) => context.balance < context.itemPrice,
},
transitions: [
{
event: "pay",
targetState: "SELECTING",
guards: [
{ guard: "hasEnoughBalance", targetState: "CONFIRMED" },
{ guard: "hasInsufficientBalance", targetState: "PAYING" },
],
},
],
}型パラメーター
Context
Context extends BaseContext = BaseContext
The context type
EventPayloadMapping
EventPayloadMapping = any
Mapping of event names to their payload types
StateNames
StateNames extends string = string
Union type of all valid state names
EventOutputMapping
EventOutputMapping extends Partial<Record<keyof EventPayloadMapping, unknown>> = DefaultOutputMapping<EventPayloadMapping>
Optional mapping of events to their output types
プロパティ
guards?
optionalguards:Record<string,GuardFunction<Context>>
Optional mapping of guard names to guard functions. Guards defined here can be reused across multiple transitions within this state by referencing them by name in the transition's guards array.
The guard functions receive the context parameter typed with the Context type parameter, not BaseContext, so you get full type safety for your context properties.
name
name:
StateNames
Name of this state
onEnter()?
optionalonEnter: (context,fromState) =>void
Optional callback when entering this state
パラメータ
context
Context
fromState
StateNames
戻り値
void
onExit()?
optionalonExit: (context,toState) =>void
Optional callback when exiting this state
パラメータ
context
Context
toState
StateNames
戻り値
void
transitions
transitions:
TransitionDefinitionUnion<Context,EventPayloadMapping,StateNames,EventOutputMapping>[]
Transitions available from this state