Closed matb33 closed 5 years ago
Could we do:
@machine Things
Loading
done -> Showing
error -> Error
back -> Loading
Is that the same thing? Or would XState exit and re-enter the Loading
state?
Yep, XState will exit and re-enter. It's also a fairly known pattern now too. If you look at the xstate visualizer default example, they do it there (https://statecharts.github.io/xstate-viz/)
...
failure: {
on: {
RETRY: undefined,
},
type: 'final'
}
...
Note for myself:
When implementing support for this, add |
as a symbol
in the tokenizer.
Then in the parser handle the ->
symbol followed by the |
symbol appropriately.
When compiling to XState the transition should be compiled to:
{
...
"on": {
"my event": {
"actions": []
}
}
...
}
Reason being is that the compiler leverages JSON.stringify
and if we simply set the transition target to undefined
then no property will be written to the compiled XState statechart since when stringifying undefined
props are stripped.
See: https://xstate.js.org/docs/guides/transitions.html#forbidden-transitions
We should explore a way to re-create
event: undefined
. Here's a potential example:While "loading" things, we don't want
back
to bubble up. But with the other states, it's fair game.