-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
After actions don't trigger when rehydrating state using State.from #294
Comments
When a delayed transition occurs, a special action is internally sent to send a timer event after the specified delay. However, when you specify the
The modified code below works: import { Machine, State } from "xstate";
import { interpret } from "xstate/lib/interpreter";
const stateChart = {
context: {},
initial: "ping",
states: {
ping: {
after: {
1000: "pong"
}
},
pong: {
after: {
1000: "ping"
}
}
}
};
const machine = Machine(stateChart);
const service = interpret(machine);
service.onTransition(current => console.log(current.value));
service.start(); |
@davidkpiano Sure it works if you don't pass an initial state to the interpreter and set the initial up front. However that wasn't the issue here. I want to be able to enter the state machine with a specific context at any point of the machine when restoring the system. Therefore I'm not using the initial state but What if I wanted to start the above machine on the pong state state with an arbitrary context? Now the delayed transition on that wouldn't trigger. Thanks for your reply! |
There's two approaches to this:
|
Bug or feature request?
Bug
Description:
I am trying to resume an interpreter using a state as the argument when starting. However the
after
actions on that state do not trigger leaving my interpreter stuck in that state.(Bug) Expected result:
State transition after the specified time.
(Bug) Actual result:
Interpreter waiting for further input.
(Bug) Potential fix:
I haven't had a chance to look at the source code for Xstate, but I did find a very dirty workaround. I added an extra
loading
state to my machine that I will load up first and then transition into the actual state I want to restore to. This way everything works as expected.Link to reproduction or proof-of-concept:
Here's a code sandbox that illustrates the problem:
Here's the actual code of my minimal example for easy reference:
The text was updated successfully, but these errors were encountered: