react-automata
react-automata copied to clipboard
Actions are not updated when the transition is to the same state
With a statechart that looks like this, where an event triggers a transition to the same state, its associated actions
are not updated unless transition
is called with the second (data) argument.
const statechart = {
initial: "login",
states: {
login: {
on: {
error: {
login: {
actions: ["showErrorMessage"]
}
},
success: {
welcome: {
actions: ["showSuccessMessage"]
}
}
}
},
welcome: {}
}
};
doesn't work: transition('error')
works: transition('error', {})
Here is a reproduction.
Updated: this works if you pass in an empty object as the second arg to transition
Thank you very much for opening this issue, providing a non-working example and a workaround, @good-idea.
I didn't consider the case where a transition goes back to the current state on purpose, and I strongly believe we should cover the case. I left some comments in the PR, and I'm looking forward to merging it.