Skip to content

@ue-too/being / index / StateDefinition

インターフェイス: StateDefinition<Context, EventPayloadMapping, StateNames, EventOutputMapping>

定義: schema-factory.ts:163

Definition of a single state in the state machine.

typescript
{
  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?

optional guards: Record<string, GuardFunction<Context>>

定義: schema-factory.ts:188

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

定義: schema-factory.ts:172

Name of this state


onEnter()?

optional onEnter: (context, fromState) => void

定義: schema-factory.ts:190

Optional callback when entering this state

パラメータ

context

Context

fromState

StateNames

戻り値

void


onExit()?

optional onExit: (context, toState) => void

定義: schema-factory.ts:192

Optional callback when exiting this state

パラメータ

context

Context

toState

StateNames

戻り値

void


transitions

transitions: TransitionDefinitionUnion<Context, EventPayloadMapping, StateNames, EventOutputMapping>[]

定義: schema-factory.ts:174

Transitions available from this state