I'm building an actor system comprised of a manager actor which spawns a varied number of worker actors. Interaction with the system is done through a service which only sends events to the manager. I'd like to DI some actors and actions implementations to the worker actors. Is there an idiomatic way to do this? Before the manager was involved, I was doing this:
// some-service.ts (BEFORE)
const workerActor = createActor(
workerMachine.provide({
actors: workerActors,
actions: workerActions,
}),
{
input: { /* ... */ },
},
).start();
But now that the manager is spawning them, I'm not sure. Currently here:
// some-service.ts (CURRENT)
const managerActor = createActor(managerMachine).start();
// manager-machine.ts
const managerMachine = setup({
/* ... */
actors: {
workerMachine,
},
actions: {
spawnWorkerActor: assign({
workerActors: ({ event, spawn }) => {
/* ... */
const workerActor = spawn('workerMachine', {
systemId: 'someSystemId',
id: 'id-from-event',
input: {
/* stuff from event */
},
});
/* ... */
},
}),
},
}).createMachine({
/* ... */
});
I'm probably too deep and just over-thinking it. Help? 🙂