-
I'm trying to wrap my head around xState and don't understand something. In functional languages I define states using discriminated unions like...
So each state has unique data for that state. So if I want to draw the Error state I can write "Something went wrong: {Error}" In xState it doesn't seem like this is how it works. It looks like one Context is shared by all the possible states. So an Error message exists for all states, though it might be null or undefined for some. Is this correct? And if so, is that a technical limitation or the way we really want it to work? As a side note I did build my code using a hand made type-safe Typescript function. Action -> State -> State. I sprinkled in some side effects. It works but it was super tedious to write with all the Switch statements. Doesn't do hierarchical or history or visualization but it works. So I thought maybe xState would make this easier (and a lot shorter) and ran into the conceptual problem described above. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 11 replies
-
I'm not familiar enough with functional languages to know how this works there but in TypeScript this ain't super trivial right now. You can actually use typestates to achieve what you want but note that this is not type-safe. |
Beta Was this translation helpful? Give feedback.
I'm not familiar enough with functional languages to know how this works there but in TypeScript this ain't super trivial right now. You can actually use typestates to achieve what you want but note that this is not type-safe.