Once a machine ends its execution, it should enter in a "final" state. That means that no more actions can trigger any machine state change.
Also, for compound machines, when the child enters in the final state and executes the onEntry handlers of the final state, it will also internally emit state.done.{id}, where id is the name of the owning machine.
More details are available on the official documentation.
There may be multiple final nodes, so it would be to have a boolean final to indicate that the state is final.
{
"key": "light",
"initial": "green",
"states": {
"green": {
"on": {
"TIMER": "yellow"
}
},
"yellow": {
"on": {
"TIMER": "red"
}
},
"red": {
"on": {
"state.done.red": "green"
},
"initial": "walk",
"states": {
"walk": {
"on": {
"PEDTIMER": "wait"
}
},
"wait": {
"on": {
"PED_TIMER": "stop"
}
},
"stop": {
final: true // <= addition here
}
}
}
}
}
This is part of the standard SCXML definition: final
Just a note to self:
Immediately thereafter, if the parent
is a child of a element, and all of the 's other children are also in final states, the Processor must generate the event done.state.id where id is the id of the element.
So the "done.state.STATE_ID" event will be generated for each state that reaches a final substate, and also for parallel states where all of its children have reached their final substates.
I'm wondering if an onFinal: [...] property would be appropriate as sugar for on: { 'done.state.STATE_ID': ... }.
EDIT: this is onDone now.
The syntax for this in V4 will be:
const machine = Machine({
// ...
states: {
foo: {
type: 'final'
}
}
});
Closing - this is in master and will be in 4.0.
Most helpful comment
The syntax for this in V4 will be: