#Transition / action order

1 messages · Page 1 of 1 (latest)

nimble turtle
#

If I have a transition that targets a state, and also triggers an action, will the action happen before or after the state is transitioned to (and that state's entry actions are triggered)?

Basically the state I'm targeting stores the event data in context, and the action I'm triggering wants to use the data that's in context.

humble tundra
#

A transition's actions happen after the transition exits all of its states (exit actions are executed), but before entering states (before entry actions)

nimble turtle
#

hmm, guessed as much

#

trying to figure out the right way to model this

humble tundra
nimble turtle
#

@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

humble tundra
#

its the model that is important, not the exact extended state 🙂

#

just need a minimal example as well

nimble turtle
#

just awkward to have to strip out all the types

nimble turtle
#

@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

humble tundra
#

sure, there are a couple of options:

  1. That action isnt an entry action, it should be on “server says is logged in” transition
  2. you can use the choose action creator to conditionally execute an action
#

I would prefer 1 if i understand your use case

nimble turtle
#

@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

humble tundra
#

Oh i see, misread the the actions