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
onEnter does not execute if state is initialState #2
Comments
Let me have a look. I will set up a unit test. I've just released an update and setting page breaks on states now works nicely. |
I've just released 0.13 which has a fix for it. I'm also interested in any details you care to share about how you are using the library. |
Thanks for the update, i will give it a try later today. As for my use case i was trying to implement something like this. MyContext context;
StateMachine.create((g) => g
..initialState<StateA>()
..state<StateA>((b) => b
..onEnter((_, __) async {
final data = await loadDataA();
context = context.udpdate(data);
machine.applyEvent(GoNext);
})
..on<GoNext, StateB>()
)
..state<StateB>((b) {})); |
Also what i don't understand is why the transition/onEnter has to be async? Looking at other statemachines (xstate for example) the transition is always sync. |
I decided on Async for maximum flexibility.
If you need to do a network call during onEnter or a sideEffect then they
need to be Async so you can force the state machine to wait for the network
call to complete.
…On Thu, 10 Dec 2020, 9:00 pm Michael, ***@***.***> wrote:
Also what i don't understand is why the transition/onEnter has to be
async? Looking at other statemachines (xstate for example) the transition
is always sync.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAG32OFGYWFGECLDCP2AJEDSUCL2FANCNFSM4USGR7KQ>
.
|
Is there a way to test against a parallel, nested machine? if (machine.inState([Login, User, IsValid]) && machine.inState([Login, Email, IsValid])) {
return FooWidget();
} I am using the IsValid Type twice but in different parallel states |
Firstly the FSM should throw an error if you try to use the same state twice. If it doesn't now it will shortly:) We could add a method like the above suggestion but I'm concerned you are trying to solve the problem in the wrong way. Instead you should consider collapsing the coregions down to a single state with an onjoin. Note I found problems with onjoin yesterday for which I've pushed a fix but I still need to fully test it which is today's job. |
Can you provide some more detail around what you are trying to do. One of the issues I'm grappling with is what api's we need to make fsm2 integrate nicely with flutter. Having to make calls to 'isInState' feels like the fsm2 api isn't doing the right thing. If you can provide a worked example maybe we can come up with a better solution. |
I've just published 0.15.0 which has fixes for onJoin. |
I had no particular use case. I am just trying to see how this statemachine works :)
class StateA implements State {}
class FromAToB implements Event {}
class StateB implements State {}
class StateC implements State {}
test('foo', () async {
int i = 0;
StateMachine machine;
machine = StateMachine.create((g) => g
..initialState<StateA>()
..state<StateA>((b) => b
..onEnter((_, __) async {
await Future.delayed(Duration(microseconds: 10));
machine.applyEvent(FromAToB());
})
..on<FromAToB, StateB>())
..state<StateB>((b) => b
..initialState<StateC>()
..state<StateC>((b) => b
..onEnter((_, __) async {
i = 1;
}))));
await machine.waitUntilQuiescent;
expect(i, equals(1));
}); This would be an actual use case for me, where i have to request some async data in |
Sorry my question was more around how you intend to wire it into flutter? |
Oh i think i would use final state = useProvider(myMachine.state);
if (state.inState(Loading)) {
return ActivityIndicator();
} else if (state.inState(Data)) {
return MyDataWidget();
} else {
throw StateError();
} |
Hi, i am doing some tests using your great lib :)
Unfortunately i am running into a problem where
onEnter
does not executeonEnter
will never execute if you are using.initialState<>
. This does also not work for nested trees.I am using version
0.10.1
The text was updated successfully, but these errors were encountered: