statelyai / xstate-tools

Public monorepo for XState tooling

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature request: support for self-transitions without explicit `target` in the Visual Editor

ethan-butler opened this issue · comments

xstate supports self-transitions without a target value. The behavior is that actions are executed but without updating the state. Adding these types of self-transitions to the top level of the machine is incredibly useful for situations where a machine might want to allow context values to be updated by subscriptions to external services (in my team's case, WebSocket events).

Here's a simple example of this type of pattern.

Screen Shot 2023-03-03 at 7 48 36 AM

As far as I can tell, it's not currently possible to create this type of transition using the Visual Editor because the drop-down for targets only has an option for explicit states.

Screen Shot 2023-03-03 at 7 55 04 AM

The result is that self-transitions on the machine cause the machine to reset to its initial state. Our workaround right now is just deleting the target field in code. I'd love an "empty" option in the dropdown. (This is really only useful for the machine itself – the current set of options works great for self-transitions on individual states.)