#Can `self` be available in a guard the way actions is?
1 messages · Page 1 of 1 (latest)
cc. @keen hawk I know you had thoughts on this
this would be quite useful if possible! is there a workaround? not having this will force me to put this state in context, just so it can be available in a guard, when it would be better modeled as a specific state in the machine
Depends on your use-case: can you share an example of how you'd like to check the state in a guard?
i have a parallel machine where one state is called Auth and it determines if person is logged in or not, then i have another state called List which on a SAVE event should go to a Saving state but only if the Auth state matches LoggedIn, otherwise the List state should not transition
Ahhhh okay
im faced with putting the auth state in to context instead of as it's own parallel state just so i can check its value
I'm glad I asked. Would this be helpful? https://stately.ai/docs/guards#in-state-guards
A guard is a condition function that the machine checks when it goes through an event. If the condition is true, the machine follows the transition to the next state. If the condition is false, the machine follows the rest of the conditions to the next state.
on: {
event: {
guard: stateIn('#state1');
},
anotherEvent: {
guard: stateIn({ form: 'submitting' })
}
}
oh exactly
yes
though sometimes i want to combine the value with a value in context
thats why i just wish i had self but yeah thatll do the job
guard: and([stateIn(...), yourCustomGuard])```
Not exactly - difficult to type that