Class: Automaton

wk/pattern/automaton/Automaton~ Automaton

Implements a class the objects of which are finite automatons (state machines).

new Automaton(automaton)

A finite automaton is in exactly one of a finite number of states at any given time. Initially it is in the initial state.

Whenever an action is performed, it changes its state due to the transition table given. The new state depends on the current state and the action performed.

On exiting a state the automaton dispatches the exit event of that state (if that event exists). Then it dispatches the do event of the current transition (if that event exits). On entering a state, it dispatches the entry event and then the do event of that state (if those events exist). If a transition does not lead to a new state, i.e., if the automaton remains in the current state, neither the exit event nor the entry event but only the do event of the transition an the do event of that state are dispatched.

In the transition table there can be noted a default action for every state. Whenever the automaton is in a specific state and there is no entry found for the current action, the default action is performed instead. If no default action is found, too, the automaton remains in the current state and an error event is dispatched (if it exists).

Parameters:
Name Type Description
automaton Object
Properties
Name Type Argument Default Description
initialState string The initial state of the automaton.
defaultAction string <nullable>
An action that is performed, if the action to be performed does not exists.
errorEvent string <nullable>
This event is dispatched, if no transition is found (neither for the action passed to the automaton nor for the default action).
states Object.<string, {entry: ?(string|function()), do: ?(string|function()), exit: ?(string|function())}> <optional>
{} An object that defines the entry, do, and exit actions (functions) or events (strings) of states of the automaton. Those actions are optional. If a state has no dedicated actions, it may or may not be stated here.
transitions Object.<string, Object.<string, (string|{state: string, do: ?(string|function())})>> <optional>
{} The transitions of the automaton. For each possible state of the automaton an object containing all possible actions that can be performed in that state is to be declared. For each action the new state has to be declared. Additionally an do action (Function) or event (string) may may be added.
Properties
Name Type Description
* Object The states of the automaton.
Properties
Name Type Description
* Object The action associated with the corresponding state.
Properties
Name Type Argument Description
state string The new state the automaton switches into after the action has been performed.
do string <nullable>
An optional reaction (do action) of the automaton when an action is passed to it (while it is in the corresponding state).
Source:

Members


lastAction

Source:

previousState

Source:

state

Source:

Methods


action(p_action)

Performs an action on the automation. It reacts by changing its state an dispatching appropriate events.
Parameters:
Name Type Description
p_action string
Source:

reset()

Resets the automaton to its initial state;
Source: