-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Eventless transitions #10
Comments
I am open to considering this, but I have some initial hesitancy and would like to understand the potential use case(s) better. My hesitancy is that this adds a lot of complexity and (imho) makes an fsm more difficult to reason about. With the current behavior, an event invocation results in This also opens the door to strange edge cases that would need to be dealt with – e.g., an infinite state change loop. @morungos (or anyone else interested in this feature) – can you share more about the use cases / scenarios that are driving this request? Thanks! |
Sure. Our main use case was the navigation state in a component. We want the application to be able to, for example, go to the login state, but if it is already logged in, to automatically transition to that state without some derived store having to somehow to swallow the additional states, which might trigger fast renders of components before it settled into a final state. In effect, directing to a login state might transiently flash a login screen even if you're already logged in. We did attempt to use a derived store to skip transitional states but turned out to be somewhat more complex than the entire FSM, and it required unpacking the states into pre-states so we'd know when to ignore. In effect, we would have needed to restructure the state design significantly to make it possible, and even then we'd have a substantially more complex system, with very tight coupling between these two components, when really all we needed was to hide transitory states from the application. There are other examples, but they were more or less equivalent -- in every case we wanted to be able to request a state, and then, if certain guard conditions were met, eventlessly fall through into a more appropriate state (each state more or less corresponded to a screen) without rendering all the screens along the way. xstate, for example, does have eventless transitions -- in its full version -- and they are an accepted part of state charts. Our logic pretty much followed the state charts description: we always need to guarding against certain conditions. And yes, there absolutely is the risk of creating an infinite loop if you get it wrong. There's a warning to that effect on the xstate pages. In fact, there is anyway, even if you attempt to achieve that with a derived store. In fact, it's worse with a derived store because you're now fighting Svelte's stores as well as the FSM. But, of course, we'd far rather use this module than xstate, which would more or less double our deployment footprint for this one small requirement. |
Hi, has there been any movement towards implementing eventless transitions? |
@morungos thanks for sharing the details above – this was very helpful. I'm working to implement this. For consistency, you will be able to return a state from I'll push a public branch soon for feedback. |
@kenkunz You might want to look at: morungos@0955042, which was my implementation. There's also a few tests. It might give you some ideas. |
Opening a new issue to consider / discuss the possibility of adding Eventless Transitions, as proposed by @morungos:
Originally posted by @morungos in #8 (comment)
Proposed feature / API change
The proposed change is to allow
_enter
lifecycle actions to return a new state, which may result is a chain of synchronous state changes from a single event invocation. Subscribers would only be notified after the final state change (and only if the resulting state is different that the pre-event state).The text was updated successfully, but these errors were encountered: