• Create a state machine that transitions based on events

    Type Parameters

    • TState extends string
    • T = ApiCallback<string>

    Parameters

    • initialState: TState

      The initial state

    • transitions: Record<TState, Record<string, ((msg) => TState)>>

      Object mapping states to event handlers

    Returns {
        get state(): TState;
        unsubscribe: (() => void);
    }

    Object with current state and unsubscribe function

    • get state(): TState
    • unsubscribe: (() => void)
        • (): void
        • Returns void