TransitionMap

November 21, 2016 ยท View on GitHub

TranistioMap is the main logic class behind StateMachine's functionality. It stores available states and actions, and the relationships between them in a ValueMap.

StateMachine uses it for its main functions, so you shouldn't need to ue it directly, but there may be times, if you have some custom logic, that you might want to directly query states and actions in more detail.

Transition modification

# add(action, from, to)

Add a new transition.

# remove(state)

Remove an existing state. If the removal causes any orphaned states or actions, these are removed as well.

Querying states and actions

# getActionsFrom(from, asMap = false)

Gets an array of available action strings from a state.

This function returns a list of string actions, unless asMap is passes, then an object of action:state pairs is returned.

# getActionFor(from, to)

Gets a single string action (if available) for another state. You would normally use this function if you have two known states and you want to see if they are connected.

# getStatesFrom(from)

Gets an array of available string states from a single state.

# getStateFor(from, action)

Gets a single string state (if available) for another state and action. You would normally use this function if you have a known state and action and you want to see if there is a transition for that action.

# getStates()

Gets an array of all states in the StateMachine.

# getActions()

Gets an array of all actions in the StateMachine.

# get(...path)

Directly queries the ValueMap instance for a state or action.

The path argument is a dot-syntax path, created usually by a result from on() or off() that returns a nested property which StateMachine uses to store relationships, such as:

actions.*.next

# hasState(state)

Tests whether a single string state exists in the StateMachine.

# hasAction(action)

Tests whether a single string action has a transition to another state. Used by StateMachine's exists in the StateMachine.

# hasTransition(action, from, to)

Tests whether the transition from a single string state to another string state via a string action exists.

# has(...path)

Direct access to the ValueMap's has() method. Mainly used internally.