Closed CodingDive closed 4 years ago
Great that you're playing around with it! By the way, for your specific example, there might be a better way to model it. You shouldn't use state.matches()
in a guard function - that function should be part of the matched state naturally.
@davidkpiano I very rarely have the need to use state.matches
in a guard. When I do, it's typically to check the machine state of orthogonal nodes. Is there a better way to do this?
Closing this issue. stateGuard.state
is not available during the initialization of the machine. It should work right after. See the discussion here.
Is there a better way to do this?
Yes, using in
: https://xstate.js.org/docs/guides/guards.html#in-state-guards
Remodeling might also help.
Is there a better way to do this?
Yes, using
in
: https://xstate.js.org/docs/guides/guards.html#in-state-guardsRemodeling might also help.
Is it possible to us the in
predicate in choose
action? If not, would it be possible to add it as a feature?
@FadySalama Can you ask this in a discussion? https://github.com/statelyai/xstate/discussions/new
Hey, I've just started playing with the new
choose
action creator. Amazing job @Andarist and @davidkpiano. I just saw the tests and was amazed to see even nestedchoose
actions work. 🔥Description It would be very nice to pass the whole
guardMeta
object, including thestate
to the conditional expressions of thechoose
action creator.Expected Result
Passing the current state on top of
context
andevent
.Actual Result
The third argument of the condition expression callback already exists.
When I log the stateGuard, this is what I get:
However,
state
is undefined.Reproduction
I will send a PR with a failing test.
Considerations
I'm not sure if this is SCXML compatible but since any
choose
action can be translated to a regular state transition with normal guards, this shouldn't be a problem right?Additional context XState 4.9.1