Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Interpreter<TContext, TStateSchema, TEvent, TTypestate>

Type parameters

Hierarchy

  • Interpreter

Implements

  • Actor<State<TContext, TEvent, TStateSchema, TTypestate>, TEvent>

Index

Constructors

constructor

  • Creates a new Interpreter instance (i.e., service) for the given machine with the provided options, if any.

    Parameters

    • machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate>

      The machine to be interpreted

    • Default value options: Partial<InterpreterOptions> = Interpreter.defaultOptions

      Interpreter options

    Returns Interpreter

Properties

children

children: Map<string | number, SpawnedActorRef<any>> = new Map()

clock

clock: Clock

The clock that is responsible for setting and clearing timeouts, such as delayed events and transitions.

id

id: string

init

init: start = this.start

Alias for Interpreter.prototype.start

initialized

initialized: boolean = false

Whether the service is started.

machine

machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate>

The machine to be interpreted

options

options: Readonly<InterpreterOptions>

Optional parent

parent: Interpreter<any>

sessionId

sessionId: string

The globally unique process ID for this invocation.

status

status: InterpreterStatus = InterpreterStatus.NotStarted

Static defaultOptions

defaultOptions: InterpreterOptions = ((global) => ({execute: true,deferEvents: true,clock: {setTimeout: (fn, ms) => {return setTimeout(fn, ms);},clearTimeout: (id) => {return clearTimeout(id);}},logger: global.console.log.bind(console),devTools: false}))(typeof self !== 'undefined' ? self : global)

The default interpreter options:

  • clock uses the global setTimeout and clearTimeout functions
  • logger uses the global console.log() method

Static interpret

interpret: interpret = interpret

Accessors

initialState

  • get initialState(): State<TContext, TEvent, TStateSchema, TTypestate>

state

  • get state(): State<TContext, TEvent, TStateSchema, TTypestate>

Methods

[symbolObservable]

  • [symbolObservable](): this

execute

  • execute(state: State<TContext, TEvent, TStateSchema, TTypestate>, actionsConfig?: MachineOptions<TContext, TEvent>["actions"]): void
  • Executes the actions of the given state, with that state's context and event.

    Parameters

    • state: State<TContext, TEvent, TStateSchema, TTypestate>

      The state whose actions will be executed

    • Optional actionsConfig: MachineOptions<TContext, TEvent>["actions"]

      The action implementations to use

    Returns void

nextState

  • nextState(event: Event<TEvent> | Event<TEvent>): State<TContext, TEvent, TStateSchema, TTypestate>
  • Returns the next state given the interpreter's current state and the event.

    This is a pure method that does not update the interpreter's state.

    Parameters

    • event: Event<TEvent> | Event<TEvent>

      The event to determine the next state

    Returns State<TContext, TEvent, TStateSchema, TTypestate>

off

  • off(listener: (...args: any[]) => void): Interpreter<TContext, TStateSchema, TEvent, TTypestate>
  • Removes a listener.

    Parameters

    • listener: (...args: any[]) => void

      The listener to remove

        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns Interpreter<TContext, TStateSchema, TEvent, TTypestate>

onChange

  • Adds a context listener that is notified whenever the state context changes.

    Parameters

    Returns Interpreter<TContext, TStateSchema, TEvent, TTypestate>

onDone

onEvent

  • Adds an event listener that is notified whenever an event is sent to the running interpreter.

    Parameters

    Returns Interpreter<TContext, TStateSchema, TEvent, TTypestate>

onSend

  • Adds an event listener that is notified whenever a send event occurs.

    Parameters

    Returns Interpreter<TContext, TStateSchema, TEvent, TTypestate>

onStop

  • Adds a listener that is notified when the machine is stopped.

    Parameters

    Returns Interpreter<TContext, TStateSchema, TEvent, TTypestate>

onTransition

  • onTransition(listener: StateListener<TContext, TEvent, TStateSchema, TTypestate>): this

send

  • Sends an event to the running interpreter to trigger a transition.

    An array of events (batched) can be sent as well, which will send all batched events to the running interpreter. The listeners will be notified only once when all events are processed.

    Parameters

    Returns State<TContext, TEvent, TStateSchema, TTypestate>

sender

  • sender(event: Event<TEvent>): () => State<TContext, TEvent, TStateSchema, TTypestate>
  • Returns a send function bound to this interpreter instance.

    Parameters

    • event: Event<TEvent>

      The event to be sent by the sender.

    Returns () => State<TContext, TEvent, TStateSchema, TTypestate>

      • (): State<TContext, TEvent, TStateSchema, TTypestate>
      • Returns State<TContext, TEvent, TStateSchema, TTypestate>

spawn

spawnMachine

  • spawnMachine<TChildContext, TChildStateSchema, TChildEvent>(machine: StateMachine<TChildContext, TChildStateSchema, TChildEvent>, options?: { autoForward?: undefined | false | true; id?: undefined | string; sync?: undefined | false | true }): SpawnedActorRef<TChildEvent, State<TChildContext, TChildEvent>>
  • Type parameters

    • TChildContext

    • TChildStateSchema

    • TChildEvent: EventObject

    Parameters

    • machine: StateMachine<TChildContext, TChildStateSchema, TChildEvent>
    • Default value options: { autoForward?: undefined | false | true; id?: undefined | string; sync?: undefined | false | true } = {}
      • Optional autoForward?: undefined | false | true
      • Optional id?: undefined | string
      • Optional sync?: undefined | false | true

    Returns SpawnedActorRef<TChildEvent, State<TChildContext, TChildEvent>>

start

  • start(initialState?: State<TContext, TEvent, TStateSchema, TTypestate> | StateValue): Interpreter<TContext, TStateSchema, TEvent, TTypestate>
  • Starts the interpreter from the given state, or the initial state.

    Parameters

    • Optional initialState: State<TContext, TEvent, TStateSchema, TTypestate> | StateValue

      The state to start the statechart from

    Returns Interpreter<TContext, TStateSchema, TEvent, TTypestate>

stop

  • stop(): Interpreter<TContext, TStateSchema, TEvent, TTypestate>
  • Stops the interpreter and unsubscribe all listeners.

    This will also notify the onStop listeners.

    Returns Interpreter<TContext, TStateSchema, TEvent, TTypestate>

subscribe

  • subscribe(observer: Observer<State<TContext, TEvent, any, TTypestate>>): Subscription
  • subscribe(nextListener?: undefined | ((state: State<TContext, TEvent, any, TTypestate>) => void), errorListener?: undefined | ((error: any) => void), completeListener?: undefined | (() => void)): Subscription

toJSON

  • toJSON(): { id: string }

Generated using TypeDoc