#Transition / action order
1 messages · Page 1 of 1 (latest)
A transition's actions happen after the transition exits all of its states (exit actions are executed), but before entering states (before entry actions)
feel free to share an example https://stately.ai/viz
Visualizer for XState state machines and statecharts
@humble tundra hmm, all my types are defined using zod, and the viz doesn't let me import 3rd party libraries
not exactly sure how I'm supposed to get around that
its the model that is important, not the exact extended state 🙂
just need a minimal example as well
just awkward to have to strip out all the types
@humble tundra I guess one simple question is, is there a straightforward way to trigger an action when a state is entered unless it was triggered by a certain type of event
in my case, I don't want to broadcast login state change if the change was itself triggered by a broadcast message
sure, there are a couple of options:
- That action isnt an entry action, it should be on “server says is logged in” transition
- you can use the
chooseaction creator to conditionally execute an action
Documentation for XState: State Machines and Statecharts for the Modern Web
I would prefer 1 if i understand your use case
@humble tundra the tricky thing is that I want to broadcast the login state based on the initial context, but also in response to the SERVER_SAYS event
the former requires getting the user data from context, the latter requires getting it from the event
that's why it's feeling awkward
I think I might be able to get around it by just not broadcasting the initial state from the server, and instead only broadcasting in response to explicit "I just logged in / logged out" events
which might be the way it should behave anyway
Oh i see, misread the the actions