Question
in xstate, actions are executed even if there is no "reel" transition.
In the exemple below, when I send transition run, new state has logRun as action.
javascript
const machine = Machine({
initial: 'a',
states: {
a: {
on: {
run: {
actions: ['logRun']
}
}
}
}
})
I wonder whether it is a normal behavior, a good practice.
Find code here
This kind of transition is a "targetless transition", related to #134. And mentioned in the SCXML spec.
Right, and this in particular is an "external" transition - where the state enters and exits itself. This will also occur with an "internal" transition (internal: true) because the action is defined on the transition itself.
It's actually quite useful! Imagine a counter machine (v4):
{
on: {
// Update extended state but don't change finite state
INCREMENT: { actions: assign({ count: ctx => ctx.count + 1 }) }
}
}
thanks for reply.
Totally agree, it's quite useful, but I was not sure it was expected.