Replies: 2 comments 15 replies
-
Thank you for your feedback and observation. Statebot has two methods that deal with upcoming states: Unfortunately I don't think they quite line-up with the specification you linked-to because Events can be specified in #performTransitions for example, but these are applied more like However, I wouldn't say that the scenario you outline is impossible to implement with Statebot, but perhaps it may be tricky to make it elegant within a single machine. Take this contrived example: [entering-email] -> email-valid | email-invalid
email-invalid -> entering-email
email-valid -> [entering-password]
[entering-password] -> password-valid | password-invalid
password-invalid -> entering-password
password-valid -> [form-completed]
[form-completed] Using the above chart, perhaps an email-form might look something like: const emailHasValidFormat = machine.inState('email-valid')
const submittedInvalidEmail = machine.history().includes('email-invalid')
return (
<form>
<input type="text" name="email" />
{submittedInvalidEmail && (
<p>Your email is invalid. Please try again.</p>
)}
<submit disabled={!emailHasValidFormat}>Submit</submit>
</form>
) As you can see, only #inState was required in this case. I can imagine such examples could be solved with more than one Statebot, which might keep each one simple rather than try to have an exhaustive chart as I've tried to attempt in the above thrown-together example. Happy to hear more on it though. Do you have a more complete example? |
Beta Was this translation helpful? Give feedback.
-
Thank you so much! In the meantime, I refactored my current Construct project to make use of Statebot instead of a bunch of global variables and things are so much cleaner and shorter this way. When using the new methods, the inner workings of the interface state management will be even more streamlined. I especially enjoy the verbose log messages as they point me to the right direction when things are just not yet working quite right. In a day or two, I will also find the time to buy you some coffee, btw :) |
Beta Was this translation helpful? Give feedback.
-
Hello,
Thanks for sharing your state machine project, I like it a lot, however, I'm missing at least one feature: in (for example) Dave Stewart's "proof of concept" FSM it is possible to query the transition chart to see if an action is available from the current state, meaning if emitting a particular event would result in a transition or not.
see: https://github.com/davestewart/javascript-state-machine/blob/master/docs/api/statemachine.md#canDo
This would be particularly useful to update GUI elements based on the result of such a function call. When emitting an event would result in no state change then I need to disbale buttons in advance, for example.
Beta Was this translation helpful? Give feedback.
All reactions