-
I know the problem is me not understanding the correct patterns. I appreciate your patience with this very linear thinker 😄 I'm coding a relatively simple solitaire dice game. The main complexity is that at various points throughout the game, the player has access to certain powers, and the engine needs to pause at these points for input. Here's an extract from the state chart: searching: {
initial: "settingup",
entry: ["setSearchStage"],
states: {
settingup: {
always: [
{
target: "assigning",
cond: "interruptsResolved"
},
{
target: "interruptingSetup"
}
]
},
interruptingSetup: {
exit: ["resolveInterrupt"],
on: {
RESOLVE: "settingup"
}
},
assigning: { So when entering the The problem is that the Thanks for your time! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Hello! Could you call the action
This would mean it gets called and the context resolved before it reaches the 'searching' state. |
Beta Was this translation helpful? Give feedback.
-
I feel bad that this has completely gone off from the original question, Thank you again for your time. So it now appears to be working as expected. Since my context is a class, I had to mark the class as "immerable" first. Then I was able to delete the previous action that was defined in the machine definition and replace it with a constant assigner function defined outside of the machine, as follows: import { assign } from '@xstate/immer';
const setSearchStage = assign<MyContext, MyEvents>((context, event) => {
const data = {};
/* A bunch of logic to populate `data` */
context.data = data;
});
/* Start of machine definition */
searching: {
initial: "settingup",
entry: [setSearchStage],
exit: ["leaveArea"],
states: {
settingup: {
/* Rest of machine definition */ So I will mark the question as answered, but people will have to read down to see that my original question was misguided in the first place. Thanks for the help! |
Beta Was this translation helpful? Give feedback.
I feel bad that this has completely gone off from the original question, Thank you again for your time.
So it now appears to be working as expected. Since my context is a class, I had to mark the class as "immerable" first. Then I was able to delete the previous action that was defined in the machine definition and replace it with a constant assigner function defined outside of the machine, as follows: