Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Wait for state with always transition#5374

Answeredbydavidkpiano
alexamy asked this question inQ&A
Discussion options

Hi!

For state that have onlyalways transition, how to assert that the machine is (or was) in that state?

Sincealways transitions are synchronous,waitFor helper cannot be used for that. Evensubscribe does not show this state.

Sandbox (open devtools console in browser to see logs):https://stackblitz.com/edit/vitejs-vite-fb8gt9ws?file=src%2Fmain.js

You must be logged in to vote

You can use the inspection API and listen for@xstate.microstep inspection events:https://stately.ai/docs/inspection

constactor=createActor(machine,{inspect:(inspectionEv)=>{if(inspectionEv.type==='@xstate.microstep'){// ...

Replies: 3 comments

Comment options

You can use the inspection API and listen for@xstate.microstep inspection events:https://stately.ai/docs/inspection

constactor=createActor(machine,{inspect:(inspectionEv)=>{if(inspectionEv.type==='@xstate.microstep'){// ...
You must be logged in to vote
0 replies
Answer selected byalexamy
Comment options

@davidkpiano Hi! I just want to clarify - if there is no way to use the inspection api, it is not possible to track machine state withalways transition (it's the intended design decision)?

I should mention that onlywaitFor is available in my current app setup, because it is separated from the actor initialization. Below are other solutions which I came up with, but they looks like hacks for me.

Using zero delay:

conststates={//..."current target":{after:{0:"next target"}}}awaitwaitFor(actor,(snapshot)=>{returnsnapshot.matches("current target");});

Using extra event just for delaying transition:

conststates={//..."current target":{on:{"#intermediate proceed":"next target"}}}awaitwaitFor(actor,(snapshot)=>{returnsnapshot.matches("current target");});actor.send({type:"#intermediate proceed"});
You must be logged in to vote
0 replies
Comment options

That's right - examining this is only currently possible through the inspection API. If you have access to the actor, you can inspect viaactor.system.inspect(…).

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@alexamy@davidkpiano

[8]ページ先頭

©2009-2025 Movatter.jp