Options
All
  • Public
  • Public/Protected
  • All
Menu

Class FSM<Instance, State, Payload>

The main Finite State Machine manager, that holds all available actions and performs the state transitions.

Type parameters

  • Instance

  • State

  • Payload

Hierarchy

  • FSM

Index

Constructors

constructor

Properties

Protected _state

_state: State

Protected Abstract actions

actions: Action<Instance, State, Payload>[]

Protected Abstract initialState

initialState: State

instance

instance: Instance

Protected logger

logger: LoggerInstance

name

name: string

Protected options

options: FSMOptions<State>

Protected Abstract states

states: State[]

Accessors

state

  • get state(): State

Methods

afterTransition

  • afterTransition(from: State | (string | State)[], to: State, data: Payload): void
  • Handles post transition results.

    Parameters

    • from: State | (string | State)[]
    • to: State
    • data: Payload

    Returns void

beforeTransition

  • beforeTransition(from: State | (string | State)[], to: State, data: Payload): void
  • Handles a state transition preparation

    Parameters

    • from: State | (string | State)[]
    • to: State
    • data: Payload

    Returns void

canGoTo

  • canGoTo(to: State): boolean
  • Checks if can go to desired state.

    Parameters

    • to: State

      The desired state

    Returns boolean

goTo

  • goTo(to: State, data?: Payload): Promise<boolean>
  • Performs a new transition in the machine.

    Parameters

    • to: State

      The desired state

    • Optional data: Payload

      An optional payload to be passed to the machine actions

    Returns Promise<boolean>

isValidState

  • isValidState(state: State): boolean
  • Ensures the state desired is valid and registered in the machine.

    Parameters

    • state: State

      The state to be checked

    Returns boolean

onTransition

  • onTransition(from: State | (string | State)[], to: State, data: Payload): Promise<boolean>
  • Handles a state transition

    Parameters

    • from: State | (string | State)[]
    • to: State
    • data: Payload

      The transition payload passed to the fsm.goTo() method.

    Returns Promise<boolean>

pathsTo

  • pathsTo(to: State): false | Action<Instance, State>[]
  • Gets all available actions to go to a determined state.

    Parameters

    • to: State

      The desired state

    Returns false | Action<Instance, State>[]

Protected setState

  • setState(to: State): Promise<void>
  • Performs the internal state change in the machine. Should not be called directl, use "goTo".

    Parameters

    • to: State

      The destination state

    Returns Promise<void>

Generated using TypeDoc