FiniteStateMachine

FiniteStateMachine

Creates finite state machines.

Constructor

new FiniteStateMachine($data)

Description:
  • Creates a new finite state machine.
Source:
Example
const toggle = new FiniteStateMachine([

    {
        $state: 'ON',
        $transitions: [{

            $state: 'OFF',
            $condition: ({$timer}) => ($timer >= 1000)
        }]
    },
    {
        $state: 'OFF',
        $transitions: [{

            $state: 'ON',
            $condition: ({$timer}) => ($timer >= 1000)
        }]
    }
]);
Parameters:
Name Type Description
$data Array.<typestate> The representation of the finite state machine.

Methods

initiate($state)

Description:
  • Initiates the finite state machine.
Source:
Parameters:
Name Type Description
$state T The name of the state to initiate.

update($timetick)

Description:
  • Updates the finite state machine.
Source:
Parameters:
Name Type Description
$timetick number The tick duration (in ms).

Type Definitions

typestate

Description:
  • A state.
Source:
Properties:
Name Type Attributes Description
typestate.$state T The name of the state.
typestate.$onEnter typestatehandlerenter <optional>
The handler to execute when entering the state.
typestate.$onLeave typestatehandlerleave <optional>
The handler to execute when leaving the state.
typestate.$transitions Array.<typestatetransition> The transitions to given states.
A state.
Type:
  • Object

(protected) typestatehandlerenter($parameters) → {void}

Source:
Parameters:
Name Type Description
$parameters Object The given parameters.
$parameters.$previous T The previous state.
Returns:
Type
void

(protected) typestatehandlerleave($parameters) → {void}

Source:
Parameters:
Name Type Description
$parameters Object The given parameters.
$parameters.$timer number The timer of the current state.
$parameters.$next T The next state.
Returns:
Type
void

typestatetransition

Description:
  • A transition to a state.
Source:
Properties:
Name Type Description
typestatetransition.$condition typestatetransitioncondition The condition to transition to given state.
typestatetransition.$state T The given state to transition to.
A transition to a state.
Type:
  • Object

(protected) typestatetransitioncondition($parameters) → {boolean}

Source:
Parameters:
Name Type Description
$parameters Object The given parameters.
$parameters.$previous T The previous state.
$parameters.$timer number The timer of the current state.
Returns:
Type
boolean