#Is it possible to declare global machine events in stately studio?

1 messages · Page 1 of 1 (latest)

strong zenith
#

Like for example, if I have an event like "unrecoverable_error" that can be called in any state at any time.

Having trouble finding a way to declare that transition. Is that like a self transition?

vapid charm
#

Just put .on on the top level of the machine before defining any states

calm whale
#

☝️ Yes, exactly:

const machine = createMachine({
  on: {
    unrecoverable_error: {
      actions: () => console.error('oh noooooo')
    }
  },
  initial: 'whatever',
  states: {
    whatever: {...},
    another: { ... }
  }
});
strong zenith
#

ah i see, i figured I could do that directly with xstate, but is it possible to model that using the editor? thank you for the responses 🙇

calm whale
#

In the editor, you can also have "root transitions"

strong zenith
#

awesome! where can i find it?

calm whale
#

See "Self-transition"?

#

I guess that should just be "Transition" now that I think about it

strong zenith
#

ah okay!