Replies: 3 comments 7 replies
-
This would greatly help out my use case -- and this appears to be pretty straightforward (but I also don't know the codebase well enough to identify any pitfalls). |
Beta Was this translation helpful? Give feedback.
-
One consideration is that this wouldn't translate to SCXML easily. Question - what's your use case:
|
Beta Was this translation helpful? Give feedback.
-
The reason we're hesitant to give a one-size-fits-all solution to spawned/invoked actor rehydration is because it's a difficult problem to solve that doesn't have a one-size-fits-all solution. The idea of (re)hydrating a machine to start at any arbitrary state sort of goes against the whole idea of what a state machine is. It also makes it very possible to end up in impossible states. I say "sort of" because the classic solution to this is event sourcing, and "snapshotting" the state of an actor can be part of the solution, for practical purposes: https://doc.akka.io/docs/akka/current/typed/persistence-snapshot.html#snapshotting If we snapshot, it needs to be a snapshot of the entire system of actors at a single moment in time, so granular |
Beta Was this translation helpful? Give feedback.
-
I have a (backend) use-case where I need to rehydrate a stand-alone machine and then spawn it as a child of a parent machine awhile later...
The current challenge is that while
Interpreter.start()
does accept aninitialState
parameter,Interpreter.spawnMachine()
does not.In essence, I want to be able to do this:
I've prototyped this approach by monkey-patching (!!!) the Interpreter:
patchedInterpreter.ts
I'm new to XState this week, so I don't know the codebase well. Do those who know it better than I feel that this is a valid approach? Would a PR adding
initialState
toSpawnOptions
be valuable and accepted into thev4
tree?Beta Was this translation helpful? Give feedback.
All reactions