Skip to content

State Machine History

HarukaK edited this page Mar 18, 2015 · 2 revisions

A state machine transition’s History property determines which states become active in a destination state's child machines when the transition is taken to its destination or "to" state. If this destination state doesn’t contain a child machine, then History is irrelevant. If the destination state has never been active before, then it has no past history, so History doesn’t matter in this case either: each machine in the destination state enters its start state.

History matters when a state has been active before and contains child machines, because each child machine has an active state. History answers this question: When a state machine transitions back to a state, do you want to restore the last active states for its child machines from the last time this state was active?

History has three possible values:

  • None. Past history is ignored. The start state of each active machine contained in the state transitioned to — and of each active machine in any level below it — becomes the active state.
  • Shallow. For each active machine contained in the state transitioned to, the active state is the last active state. If these machines have states with active child machines, the active state of each machine is its start state. In other words, use past history only one level down.
  • Deep. For every active machine contained in the state transitioned to — and all levels below it — the active state is the last active state.
Consider the state machine shown below. The machine has three levels. The "True" state in Level 1 contains two concurrent state machines "A" and "B". In Level 2, the second state machine’s "1" state contains a state machine "C", which is in Level 3.

The states with thick outlines and bold state names were the active states in the child machines the last time the "True" state was active, such as before the last transition was made from "True" to "False" in Level 1. What happens when the transition from "False" to "True" in Level 1 occurs? This depends on the History setting of the transition from "False" to "True":

  • None. Past history is ignored, so all active child machines start running in their start states. The current states will be "1" for all child machines in Levels 2 and 3.
  • Shallow. History is used only for Level 2, the level below the "True" state in Level 1. In Level 2, the current state will be "2" for machine "A" and "1" for machine "B", since these were the last active states in the child machines at this level. In Level 3, "1" will be the active state in machine "C", since "1" is the start state, and past history is not used at this level.
  • Deep. History is used for all levels below the "True" state in Level 1. In Level 2, the current state will be "2" for machine "A" and "1" for machine "B", since these were the last active states in the machines at this level. In Level 3, "2" will be the active state in machine "C", since it was the last active state.
Note that History is a property of a transition to a state, not the state itself. This provides more flexibility, since you can have different History options for a state, depending on how it was transitioned to.
Clone this wiki locally