0

Consider the following FSM:

{
  id: 'my_machine',
  initial: 'foo',
  states: {
    foo: {
      on: { 
        TRIGGER_BAR: 'bar'
      }
    },
    bar: {
      on: {
        TRIGGER_BAR: 'bar'
        TRIGGER_FOO: 'foo'
      }
    }
  }
});

Is it possible for bar to transition to bar again via the TRIGGER_BAR event?

Paul Razvan Berg
  • 16,949
  • 9
  • 76
  • 114

1 Answers1

0

Absolutely! These are called self transitions.

A self-transition is when a state transitions to itself, in which it may exit and then reenter itself. Self-transitions can either be an internal or external transition.

By default all self-transitions are external, so they will exit and re-enter again. Read the docs to see how to change this.

In the example above, you probably wouldn't want to transition to bar again, since there is no context value update. But you could very well have an action created with assign that mutates the context.

Paul Razvan Berg
  • 16,949
  • 9
  • 76
  • 114