Description
Guards on transient states transitions are not receiving the original events. This prevents using guards based on the events data.
Expected Result
The events received in transient state transitions should be the ones that originated the transition.
Actual Result
The events received are empty.
Reproduction
https://codesandbox.io/s/xstate-null-transition-guard-ogu34
Yes - from SCXML perspective this is a bug. Fixing this right now has too high possibility of breaking our users though. We are starting to work on a new major version and fixing this will have to wait for it.
Is there any write up listing the planned features/changes of the next major version?
Some things are listed here https://github.com/davidkpiano/xstate/issues/742 - its not yet an exhaustive list though. One thing that will land for sure is 100% SCXML compatibility.
@AjaxSolutions I will start marking roadmap items as 5.0 here: https://github.com/davidkpiano/xstate/issues/742
I have discovered a workaround: the 3rd argument passed to the guard is the meta object. It contains the current state. You can get your event from it.
// your guard in the transient transition
cond: (ctx, event, meta) => {
console.log(event) // always {type: ''}
console.log(meta.state.event) // e.g. {type: 'xstate.init'} this is what you want
}
This workaround works the same whether you define your transient transition with '': {} syntax or the newer always: {} syntax.
Most helpful comment
I have discovered a workaround: the 3rd argument passed to the guard is the meta object. It contains the current state. You can get your event from it.
This workaround works the same whether you define your transient transition with
'': {}syntax or the neweralways: {}syntax.