[RFC] Detect if an event will change the state. #2476
Replies: 4 comments 4 replies
-
It might also be work adding another helper function that suggested to generate a command palette of events. David outlines what the helper function would look like:
|
Beta Was this translation helpful? Give feedback.
-
A related thought I had was that the That means we can provide a helper function: |
Beta Was this translation helpful? Give feedback.
-
I have a helper named <button
disabled={!state.can("ADDED_ITEMS", count)}
onClick={() => state.send("ADDED_ITEMS", count)}
>
Add {count} items
</button> The logic is:
The assumption there is that any action or transition would cause the state to update. I don't execute the action in order to validate that the action actually changed anything. Note that I broke this handler for certain cases when I added nested logic (ie if a handler would not pass its conditions then |
Beta Was this translation helpful? Give feedback.
-
Implemented in #2546 |
Beta Was this translation helpful? Give feedback.
-
It's quite common to want to know if will the state change if I send a given event? This is useful for when you want to generate a command palette of all of the possible commands a user can do for the given state they are it or for reusing guard logic to disable parts of a UI.
David provided a POC of small helper function that can be added to core to help with this. If we can clarify the name of this helper function it should be really easy to add and test.
Prior art:
@VanTanev's useIsXStateTransitionAvailable
Beta Was this translation helpful? Give feedback.
All reactions