@thingts/fsm-engine - v1.2.1
    Preparing search index...

    Class FsmEngine<State, Events, Context>

    Finite-state machine instance created from a definition built with FsmEngine.define.

    Each instance has its own current state, event queue, timers, and optional mutable context object.

    Type Parameters

    • State extends string
    • Events extends EventMap
    • Context = void
    Index

    Accessors

    Methods

    Accessors

    • get context(): Context

      Mutable context object associated with this FSM instance.

      This is the same object passed at instantiation time.

      Returns Context

    Methods

    • Dispatches an event to the machine.

      A top-level call to dispatch() synchronously processes the given event and any subsequently dispatched events (e.g. from actions) in a single tick, before returning.

      A re-entrant call to dispatch() adds the new event to a FIFO queue and returns immediately.

      Throws FsmEngineUnknownEventError if an event is not used anywhere in the machine definition.

      Throws FsmEngineUnhandledEventError if an event is known, but the current state provides no handler for it and no fallback handles it.

      If a guard or action throws during the processing, any remaining queued events are discarded, and the error is rethrown here.

      Type Parameters

      • K extends string

        K extends EventName<Events> - Event name type. (The auto-generated doc incorrectly shows as K extends string)

      Parameters

      Returns void

    • Enables or disables trace logging.

      When tracing is enabled, the engine logs event dispatch, guard evaluation, transition selection, and action execution. The default logger is console.log.

      Pass true or false, or an options object.

      enabled defaults to true when it's not explicitly specified.

      If logger is specified, it updates the logger function, otherwise the logger remains unchanged.

      Returns this for chaining.

      Parameters

      • Optionalarg: boolean | { enabled?: boolean; logger?: (line: string) => void }

      Returns this