Self transition

A self transition is a transition that starts and ends in the same state. When a self transition is taken, the state in question is exited and entered again.

Notation

A self transition is depicted as a segment of a circle, here with the event again attached to it.

A transition from a state to itself

Usage

Self transitions are commonly used to “restart” the current state, causing the exit actions to happen, followed by the entry actions. This also resets the timer for how long the machine has been in the state, meaning that delayed transitions start counting from 0 again.

It is important to note that self transitions (or transitions to own child states) will in fact exit the state in which the transition starts. This is important to keep in mind and can be a source of confusion, since it leads to the exit and entry actions of the state to be re-executed.

For compound states this means that all substates are exited, and its initial state is entered. This effectively restarts the compound state itself.

SCXML

In Statechart XML, a self transition uses the standard <transition> syntax, with the target the same as its containing state.

<state id="important_state">
  <transition event="again" target="important_state"/>
</state>

XState

In XState, a self transition is defined as any other transition, listing the name of the state as usual:

"important_state": {
  "on": {
    "again" : "important_state"
  }
}