Type Parameters

  • T

  • C extends Record<string, unknown>

Hierarchy

  • StatelyMachine

Constructors

  • Type Parameters

    • T

    • C extends Record<string, unknown>

    Parameters

    • initial: T
    • context: C = ...

    Returns StatelyMachine<T, C>

Accessors

  • get context(): C
  • The current context of the machine.

    Example

    machine.context
    // => { anyProps: 'any values' }

    Returns C

  • get onAny$(): Observable<StatelySuccess<T, C>>
  • Emits a StatelySuccess on all successful state changes.

    Example

    machine.onAny$.subscribe(console.log)
    // ==> { from: 'SomeState', to: 'AnotherState', context: { anyProps: 'any values' } }

    Returns Observable<StatelySuccess<T, C>>

  • get state(): T
  • The current state of the machine.

    Example

    machine.state
    // => 'SomeState'

    Returns T

Methods

  • Updates the machine to the new state and optional context.

    Emits a StatelySuccess on a successful transition.

    Emits a SAME_STATE error if you try to transition to the active state, or a NO_TRANSITION error if you try to transition to a state without a valid transition.

    Example

    machine.go(States.AnotherState, { foo: foo + 1 })
    

    Parameters

    • state: T
    • Optional context: Partial<C>

    Returns void

  • Emits a StatelySuccess only for the given state.

    Example

    machine.on$(States.AnotherState).subscribe(console.log)
    // ==> { from: 'SomeState', to: 'AnotherState', context: { anyProps: 'any values' } }

    Parameters

    • state: T

    Returns Observable<StatelySuccess<T, C>>

  • Declare all valid transitions for the machine.

    Emits an EMPTY_TRANSITIONS error on go if you forget to set the transitions.

    Example

    machine.transitions([
    { from: [States.SomeState], to: [States.AnotherState] },
    { from: [States.AnotherState], to: Object.values(States) }
    ])

    Parameters

    Returns void

Generated using TypeDoc