ixfx
    Preparing search index...

    Namespace StateMachine

    Functions for creating and driving a state machine

    See StateMachine.init to get started.

    Functions

    cloneState

    Clones machine state

    driver

    Drives a state machine.

    fromList

    Returns state transitions based on a list of strings. The last string is the terminal state. A -> B -> C -> D

    fromListBidirectional

    Returns a machine description based on a list of strings. Machine can go back and forth between states: A <-> B <-> C <-> D

    init

    Initialises a state machine

    const desc = {
    pants: ['shoes','socks'],
    socks: ['shoes', 'pants'],
    shoes: 'shirt',
    shirt: null
    isDone

    Returns true if MachineState sm is in its final state.

    isValidTransition

    Returns true if toState is a valid transition from current state of sm

    next
    normaliseTargets
    possible

    Returns a list of possible state names for sm, or an empty list if no transitions are possible.

    possibleTargets

    Returns a list of possible state targets for sm, or an empty list if no transitions are possible.

    reset
    to

    Attempts to transition to a new state. Either a new MachineState is returned reflecting the change, or an exception is thrown.

    validateMachine
    validateTransition

    Classes

    StateMachineWithEvents

    A state machine that fires events when state changes.

    Type Aliases

    DriverExpressionOrResult
    DriverOptions
    DriverResult
    DriverRunner
    DriverStatesHandler
    Machine
    MachineState

    Encapsulation of a 'running' machine description and state.

    State
    StateChangeEvent
    StateEvent
    StateHandler
    StateMachineEventMap
    StateMachineWithEventsOptions
    StateNames

    List of possible states

    StateTarget

    Possible state transitions, or null if final state.

    StateTargetStrict
    StopEvent
    TransitionCondition
    TransitionResult

    Transition result

    • 'Ok': transition valid
    • 'FromNotFound': the from state is missing from machine definition
    • 'ToNotFound': the 'to' state is missing from machine definition
    • 'Invalid': not allowed to transition to target state from the current state
    • 'Terminal': not allowed to transition because from state is the final state
    Transitions

    Maps state to allowable next states

    TransitionsStrict