react-automata icon indicating copy to clipboard operation
react-automata copied to clipboard

Actions are not updated when the transition is to the same state

Open good-idea opened this issue 5 years ago • 1 comments

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

good-idea avatar Aug 30 '18 23:08 good-idea

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.

MicheleBertoli avatar Sep 01 '18 06:09 MicheleBertoli