FiniteStateMachine

FiniteStateMachine

new FiniteStateMachine(app, transitionTable, stateFetcher, stateUpdater)

Finite State Machine

Source:
Parameters:
Name Type Description
app *

Application instance, can be null if not needed

transitionTable object

{ state: { action: { desc, when, target, before, after } } }

Action rule:

  • desc: description of this transition
  • when: pre transition condition check
  • target: target state
  • before: transforming before applying to the state, can be async
  • after: trigger another action after transition, can be async
stateFetcher function

(app, context, fetcherOpts) => state

stateUpdater function

(app, context, payload, targetState, updaterOpts) => [actuallyUpdated, updateResult]

Members

(static) OK :Array

OK result

Source:
Type:
  • Array

(static) fail

Fail with a reason

Source:

(static) ifAll

If all of the conditions in the array are met, return OK, otherwise fail with a reason.

Source:

(static) ifAny

If any of the conditions in the array is met, return OK, otherwise fail with a reason.

Source:

(static) triggerAll

Trigger all actions in the array

Source:

Methods

(async) doAction_(action, context, payload, fetcherOpts, updaterOpts)

Perform the specified action.

Source:
Parameters:
Name Type Description
action String
context *
payload *
fetcherOpts *
updaterOpts *

(async) getAllowedActions_(context, withDisallowedReason)

Get a list of allowed actions based on the current state.

Source:
Parameters:
Name Type Description
context *
withDisallowedReason boolean