Options
All
  • Public
  • Public/Protected
  • All
Menu

Your state machine should inherit the StateMachine<YourStateInterface> class.

Type parameters

Hierarchy

  • StateMachine

Index

Constructors

Properties

Accessors

Methods

Constructors

Protected constructor

  • new StateMachine(initialState: S, inputSource?: I): StateMachine
  • Constructor, requires an initial state.

    Parameters

    • initialState: S

      The initial state for this machine.

    • Optional inputSource: I

      Machine inputs.

    Returns StateMachine

Properties

Private Optional _exitState

_exitState: Readonly<S & I>

Private _history

_history: HistoryManager<S, I, this>

Private _program

_program: Map<ActivationCond<S, I>, ProgramEntry<S, I>> = new Map()

The active state machine program.

type

{Map}

Accessors

exitState

exitState:

The state at program exit. Returns undefined unless the program has ended.

history

history:

Methods

exit

  • exit(exitState?: Readonly<S>): void
  • Call this from any action to signal program completion.

    Parameters

    • Optional exitState: Readonly<S>

      The exit state to return from .run.

    Returns void

recombine

  • Combine this machine with a new one. (warning: shared variables in state may cause emergent behaviour, calls to exit() from one machine may abort early for the other)

    Type parameters

    Parameters

    • other: T

      Other machine to combine with.

    • Default value precedence: "this" | "other" = "this"

      Which machine takes precedence when there's a conflict in state variables. Defaults to 'this'.

    • Default value initialState: OS & S | StateCombiner<StateMachine<S, any>, StateMachine<OS, any>> | "current" | "initial" = "initial"

      A combined state to use for the new machine, or a custom function to combine the states. You may supply a string {'current'|'initial'} to perform automatic conversion. Defaults to 'current'.

    Returns StateMachine<OS & S, MachineInputSource>

    A hybrid event machine exhibiting the behaviour of both parents.

reset

  • reset(initialState?: S): void
  • Resets the state machine to the initial state.

    Parameters

    • Default value initialState: S = this.history.initialState

      (optional) Restart with a different initial state.

    Returns void

run

  • run(forever?: boolean): Readonly<S & I>
  • A blocking call that evaluates the state machine until it exits.

    Parameters

    • Default value forever: boolean = false

      Should we keep going even if the machine stops reacting?

    Returns Readonly<S & I>

    Returns the machine's exit state, or null if the machine halted.

step

  • step(): number
  • Advance a single tick and return.

    Returns number

    Number of actions fired during this tick.

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc