statelyai / xstate-viz

Visualizer for XState machines
https://stately.ai/viz
MIT License
434 stars 102 forks source link

Feature Request: Allow users to specify return value of guard #305

Open jonroby opened 3 years ago

jonroby commented 3 years ago

When using the visualizer, if a guard is left unimplemented as a string, users can't move between states.

As a developer (or product designer), I would like to specify the return value of a guard in the visualizer, so that I can explore the state chart by clicking on different scenarios, without having to implement the functions. In the code, developers could just use a placeholder string: { ..., cond: "myCond" }.

codingedgar commented 2 years ago

This discussion is also evaluated here https://github.com/statecharts/xstate-viz/issues/31#issuecomment-1042576083 but I'm guessing this is the main repo now?

My own comment in that other repo was:

If I chick a transition, shouldn't that mean the guard is returning true? otherwise, I would click the other transition, right? At least for the click scenario, I see the guarded transitions as two distinct transitions, I'm guessing that's not what is happening.

I'm using the viz in vscode, and there's no way (i think) to send a specific event with payload, but regardless I just want to play with the machine with clicks to make videos, as a simulation where the truth is what I click. Also for other non-tech team members, it is super useful, just an interactive diagram of what is happening based on the machine definition with strings.

I'm not sure if it is a bug, but sometimes I click a guarded transition and it takes me to another ~event~ state node that shouldn't (as if I had selected a different guarded outcome) and sometimes if I restart it works as expected, but other times it is evaluating just the same outcome from a guarded transition, and I cannot transition to certain ~event~ state node ever because the guarded transition just does not go there, it keeps choosing another scenario.

mattpocock commented 2 years ago

@codingedgar Correct, that old one should be disposed of (cc @davidkpiano)

In the visual editor, we wrote code for this exact purpose - being able to simulate a state machine without needing to run side effects in guards. I think, at some point, we may make this runner available as an alternate in the viz.

codingedgar commented 2 years ago

@codingedgar Correct, that old one should be disposed of (cc @davidkpiano)

In the visual editor, we wrote code for this exact purpose - being able to simulate a state machine without needing to run side effects in guards. I think, at some point, we may make this runner available as an alternate in the viz.

I noticed it! That was a super good idea.

Right now the visual editor does not allow me to make it look pretty (I cannot move lines or auto-organise like viz) and presentable to clients or other team members, so i wonder what could happen first, the editor looking as pretty as the viz or the viz integrating other ways of simulation. Can I contribute in some way?

(Also, the old repo has a note on the readme but probably archiving to read only would be best)