effex-monorepo
    Preparing search index...

    Interface Transition<S>

    A state machine with declarative transitions.

    interface Transition<S extends string> {
        canTransitionTo: (state: S) => Readable.Readable<boolean>;
        current: Readable.Readable<S>;
        guard: <A extends unknown[], R, E>(
            enabledStates: S[],
            callback: (...args: A) => Effect<R, E>,
            options?: GuardOptions,
        ) => (...args: A) => Effect<void | R, InvalidTransition | E>;
        is: (state: S) => Readable.Readable<boolean>;
        to: (state: S) => Effect<void, InvalidTransition>;
    }

    Type Parameters

    • S extends string

      Union type of all possible states

    Index

    Properties

    canTransitionTo: (state: S) => Readable.Readable<boolean>

    Check if transition to a state is currently allowed (reactive). Takes guards into account - returns false if guard condition is not met.

    current: Readable.Readable<S>

    Current state as a Readable (read-only)

    guard: <A extends unknown[], R, E>(
        enabledStates: S[],
        callback: (...args: A) => Effect<R, E>,
        options?: GuardOptions,
    ) => (...args: A) => Effect<void | R, InvalidTransition | E>

    Create a guarded callback that only runs when in specified states.

    Type Declaration

      • <A extends unknown[], R, E>(
            enabledStates: S[],
            callback: (...args: A) => Effect<R, E>,
            options?: GuardOptions,
        ): (...args: A) => Effect<void | R, InvalidTransition | E>
      • Type Parameters

        • A extends unknown[]
        • R
        • E

        Parameters

        • enabledStates: S[]

          States in which the callback is allowed to run

        • callback: (...args: A) => Effect<R, E>

          The callback to guard

        • Optionaloptions: GuardOptions

          Configuration for blocked behavior

        Returns (...args: A) => Effect<void | R, InvalidTransition | E>

    is: (state: S) => Readable.Readable<boolean>

    Check if currently in a specific state (reactive)

    to: (state: S) => Effect<void, InvalidTransition>

    Transition to a new state. Fails with InvalidTransition if the transition is not allowed from the current state, or if a guard condition is not met.