switchyard
    Preparing search index...

    Class State<C>

    A state is a real enum value that also carries its statechart options: static Loading = Fetch.of('loading', { children: Attempt }), in class Fetch extends State<Attempt>: the type param names the enums of its children and regions, so m.can() and m.matches() accept their states.

    Each enum declares private declare readonly brand: never. TypeScript compares classes by shape, and a private member is the one thing that tells two state enums apart.

    Type Parameters

    Hierarchy

    • Enum
      • State

    Indexable

    • readonly [index: number]: string
    Index
    "[CHILDREN]"?: (children: C) => void
    children: EnumClass<State<never>> | undefined
    final: boolean
    history: "shallow" | "deep" | undefined
    regions: Record<string, EnumClass<State<never>>> | undefined
    value: string
    • get id(): this

      Returns this

    • get label(): string

      Returns string

    • get values(): any[]

      Every instance declared as a static member, in declaration order.

      A getter so templates can read it ({{#each OrderState.values}}). TypeScript cannot give a static getter a per-subclass type, so it is any[]; annotate where it matters (const all: OrderState[] = OrderState.values).

      Returns any[]

    • Returns the primitive value of the specified object.

      Returns string

    • Type Parameters

      • T extends Enum

      Parameters

      • this: EnumClass<T>

      Returns EnumCodec<T>

    • Starts a match over the static members, checked by the compiler: .when([Cls.A, Cls.B], fn) handles members, .exhaustive() compiles only once every member is handled, and .otherwise(fn) is the catch-all.

      Type Parameters

      • C
      • T extends Enum

      Parameters

      • this: C & { prototype: T }
      • value: T

      Returns MatchOf<T, Members<C, T>>

    • Declares a member: static Pending = OrderState.of('pending'). Same instance as new, but typed as its own member, which is what lets Enum.match track what is handled.

      Type Parameters

      • T extends Enum
      • const V extends string
      • A extends unknown[]

      Parameters

      • this: new (value: string, ...args: A) => T
      • value: V
      • ...args: A

      Returns T & { value: V }

    • The instance whose value is raw, or undefined. Passing an instance returns it.

      Type Parameters

      • T extends Enum

      Parameters

      • this: EnumClass<T>
      • raw: string | T

      Returns T | undefined