-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
initialState() does not work beyond machine load #21
Comments
@bsutton thoughts on whether this might break stuff? It will cause transitions that are not explicitly defined (i.e. |
The workaround, today, is to do something like: ..state<ParentState>((b) => b
..on<_InternalPropagate, ChildState>()
..onEnter(
(fromState, event) async => _fsm.applyEvent(_InternalPropagate())) |
So the doco states: (for co-regions).
So if 'initialState' isn't being called for each child (that isn't explicitly targeted in the on or onFork) then I would consider that a bug. I agree that there is a risk that this could break existing code. Perhaps the path forward is to fix the bug and release it as 4.x with appropriate warnings of the behavior change.
Not certain I understand what you are saying here but... I'm not certain changing 'initialState' to 'activateChild' provides any great benefit but I'm open to a discussion and better terminology. The current bug and name 'initialState' does leave a user wondering if this is a one off event or each time a co-region is entered. Maybe 'defaultState' would be a better term. The state a region is in before it has been explicitly set to a state.
This is already meant to happen and I thought it was what we are were talking about with respect to the initialState not being called, so this sentence is confusing me. |
It is a bug then.
My point is if
Of course, if we conclude that
I was mainly talking about non-coregions in the ticket, but I was thinking that this should also apply to coregions. Those would not have intialState (since that's singular) but rather that when you enter a coregion state (with |
so I'm a little confused as initialState only applies on startup and for co-regions. To be clear you can't directly enter a 'parent' state as these are called abstract states. You can only ever directly enter a leaf state. The path to that leaf state then makes it explicit which parent states to activate - initialState is not needed. Only when a co-region exists is initialState needed. For co-regions, if i enter a leaf state that is within a co-region then I also enter co-states in the co-region. As I've not explicitly stated which of these is the target ,we then should use initialState (or the state that was added to the region first) to work out what the state is of those other co-states in the co-region. So are we talking about the same thing? |
So I am pretty sure this is possible (entering an abstract state). When you do, none of the child states (even with initialState() set on the abstract state) would be active. I wrote panghy@d7a2438 to show that.
Yeah this is the "bonus" I mentioned initially, but I was looking originally to make initialState() work on abstract states (after initial FSM load). |
So I am pretty sure this is possible (entering an abstract state)
Then this is the bug.
The machine should throw if you're try to do this. There is an existing
exception for this error.
…On Sat, 11 May 2024, 9:50 am Clement Pang, ***@***.***> wrote:
To be clear you can't directly enter a 'parent' state as these are called
abstract states. You can only ever directly enter a leaf state. The path to
that leaf state then makes it explicit which parent states to activate -
initialState is not needed. Only when a co-region exists is initialState
needed.
So I am pretty sure this is possible (entering an abstract state). When
you do, none of the child states (even with initialState() set on the
abstract state) would be active.
I wrote ***@***.***
<panghy@d7a2438>
to show that.
For co-regions, if i enter a leaf state that is within a co-region then I
also enter co-states in the co-region. As I've not explicitly stated which
of these is the target ,we then should use initialState (or the state that
was added to the region first) to work out what the state is of those other
co-states in the co-region.
Yeah this is the "bonus" I mentioned initially, but I was looking
originally to make initialState() work on abstract states (after initial
FSM load).
—
Reply to this email directly, view it on GitHub
<#21 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAG32OCYQMXQHJANWIDRH5LZBVMMHAVCNFSM6AAAAABHOGN5YSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBVGM4DSMRZHA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I made the fix to disallow transitioning into an abstract state: #22 This breaks existing tests (nested_test.dart): Similar test failures can be observed in The unit tests show that it is valid to enter an abstract state. We can of course change that behavior and fix the tests. This issue was filed to see whether we can keep the behavior today as-is but let |
So if you are happy to make the changes then I'm not going to object to formally allowing transitions to abstract states - particular given the existing code allows it. Need to look through the existing exceptions because I believe there are parts that prohibit it. We just need to update the documentation and add a few more unit tests. |
panghy@d7a2438
Even though the generated visualization of the FSM suggests that entering a parent state will automatically also activate its child state (prescribed by
initialState<S>()
). In reality, the automated activation of childinitialState()
only works on initial load of the FSM.Perhaps there could have been a different way to indicate that subsequent entry of the parent state should also trigger transition to a child state (perhaps instead of
initialState<S>()
, one could imagine declaringactivateChild<S>()
, with the bonus of coregions automatically activating multiple children on entry, without the need foronFork()
).The text was updated successfully, but these errors were encountered: