Metakit / @doeixd/metakit/machine

Phases

interface · packages/metakit/src/machinePhaseTypes.ts:214

interface Phases<S extends Schema.Top, P> {
  readonly phase: PhaseRefs<S['Type'], P>
  readonly within: <N extends PhaseName<P>>(
    phase: Phase<S['Type'], N, Held<P, N>>,
    holds: (
      variant: PathAccessor<S['Type'], Held<P, N>>,
    ) => ExprInput<S['Type'], boolean | null>,
  ) => ExprType<S['Type'], boolean | null>
  readonly from: <
    const Refs extends readonly [
      Phase<S['Type'], PhaseName<P>, unknown>,
      ...ReadonlyArray<Phase<S['Type'], PhaseName<P>, unknown>>,
    ],
  >(
    ...from: Refs
  ) => From<S, Schema.Struct<{}>, P, Refs[number]['name']>
}

The phases of a field and the builder of transitions between them.

Members

Phases.phase

property · packages/metakit/src/machinePhaseTypes.ts:215

readonly phase: PhaseRefs<S['Type'], P>

Phases.within

property · packages/metakit/src/machinePhaseTypes.ts:222

readonly within: <N extends PhaseName<P>>(
  phase: Phase<S['Type'], N, Held<P, N>>,
  holds: (
    variant: PathAccessor<S['Type'], Held<P, N>>,
  ) => ExprInput<S['Type'], boolean | null>,
) => ExprType<S['Type'], boolean | null>

A rule of the state scoped to one phase: true outside it, and holds of the field as the phase holds it inside it, so a variant's own fields are read where they are there (Expr.refine($ => within(phase.Confirming, confirming => …))).

Phases.from

property · packages/metakit/src/machinePhaseTypes.ts:226

readonly from: <
  const Refs extends readonly [
    Phase<S['Type'], PhaseName<P>, unknown>,
    ...ReadonlyArray<Phase<S['Type'], PhaseName<P>, unknown>>,
  ],
>(
  ...from: Refs
) => From<S, Schema.Struct<{}>, P, Refs[number]['name']>