#Searching for v5 migration advice for replacing "autoForward"

1 messages · Page 1 of 1 (latest)

teal night
#

As the "autoForward" feature is no longer supported by the xState V5, I would appreciate some advice for my migration to the v5.
I have an actor whose responsibility is to wait for an "addContainer"-event and consequently spawn several child actors.
I would like every event sent to the parent actor to be automatically forwarded to all the spawned child actors.

So far, in v4, I have been executing the following action once the "addContainer"-event was received:

assign({containerRefList: (context, event) => {
                const smActors = event.data;
                const newActors = smActors.map((actor)=> { return spawn(actor.machine, {name: actor.id, autoForward: true})});
                return [...context.containerRefList, ...newActors];
}})

In v5, how can I create the parent actor such that its received events are always sent to the actors saved in the containerRefList-context variable?

wanton tree
#
always: {
  actions: sendTo('child', ({ event }) => event)
}
#

^ This didn't work in v4 (infinite loop) but v5 is smarter about always transitions

teal night
wanton tree
#
sendTo(({ context }) => context.someChildRef, ...)
teal night