Infinite paths in @xstate/graph #1395
-
Hi, For state machines with context, it looks like For instance, the following machine const machine = Machine<{ pings: number }>({
initial: "ready",
context: { pings: 0 },
states: {
ready: {
on: {
PING: {
target: "pinging",
actions: actions.assign({ pings: ({ pings }) => pings + 1 })
},
DONE: "stopped"
}
},
pinging: {
on: {
DONE: "ready"
}
},
stopped: {
type: "final"
}
}
}); Since there is a loop between the states Is this intended behavior? Any advice on how to prevent this? Here is a link with an example sandbox |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yes, it is intended behavior. Finite states are finite; extended state (in The overall state is a combination of finite state ( You have to limit the state: getShortestPaths(machine, {
filter: (state) => state.context.pings < 10
}) |
Beta Was this translation helpful? Give feedback.
Yes, it is intended behavior. Finite states are finite; extended state (in
context
) can be infinite.The overall state is a combination of finite state (
ready
orpinging
orstopped
) and extended state (count: 0 ... ∞
)You have to limit the state: