statelyai / xstate

Actor-based state management & orchestration for complex app logic.
https://stately.ai/docs
MIT License
26.98k stars 1.24k forks source link

Request (typescript): allow spawn of "unknown" or dynamic actors #4802

Open karlanke opened 6 months ago

karlanke commented 6 months ago
          @karlanke Currently, if you specify known `actors` in `setup(…)`, you can only reference those actors in `spawn`.

Maybe we can find some way to loosen this constraint (cc. @Andarist)

Originally posted by @davidkpiano in https://github.com/statelyai/xstate/issues/4566#issuecomment-2000165955

I see the benefit here mostly for dynamic machines - if you know all of the actors up front, you might as well define them in setup() and get all the typing.

In my case, I have a large number of children, only some of which might get spawned at any given moment, and I'd like to keep them decoupled from the spawning machine (essentially, I have an interface that all the children adhere to, and I want to be able to add a new implementation and not have to update several places in code).

I could also see the benefit of loading and running machines from a remote store, where there's no knowledge at compile time of the types involved.