Open Steve-OH opened 2 years ago
As the name suggests, side-effects should not be executed inside of actions.pure
. The pure action is used to determine which actions will be executed in a pure way (returning an array rather than executing), and those actions can affect what the final "resolved" state of the transition will be; e.g., raised events from the raise(...)
action creator may result in a different state than if you weren't to execute that action.
The workaround is to wrap side-effects in actions:
doStuff: actions.pure((context) => {
return [
() => { console.log('foo'); },
send({ ... })
]
})
If:
actions.pure()
, andactions.pure()
has side effects,Then:
actions.pure()
runs every time you mouse over the transition in the visualizer.You can see this behavior in the following machine:
Run the machine, open a dev tools console, and mouse over the
doIt
transition to see the behavior. The behavior seems to solely in the visualizer, and the machine still works properly, so it's mostly an annoyance. But it can lead to developer confusion with the unexpected behavior, since sprinkling calls toconsole.log()
is a common debugging technique.