-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Description
I'm using XState v5 and trying to get the aggregated output from a Parallel State when it completes (onDone).
In XState v4 or previous discussions, it was implied that event.output in the onDone transition of a parallel state would contain the merged outputs of its child final states. However, in v5, I am getting undefined for event.output.
Here is a minimal reproduction:
import { setup, fromPromise, createActor } from 'xstate'
const machine = setup({
actors: {
worker: fromPromise(async () => ({ data: 'result' })),
},
}).createMachine({
initial: 'parallel',
states: {
parallel: {
type: 'parallel',
onDone: {
actions: ({ event }) => {
// This logs 'undefined'
console.log('Aggregated Output:', event.output)
},
target: 'end',
},
states: {
branch1: {
initial: 'working',
states: {
working: {
invoke: {
src: 'worker',
onDone: 'finished',
},
},
finished: {
type: 'final',
output: {
res1: 1,
},
},
},
},
branch2: {
initial: 'working',
states: {
working: {
invoke: {
src: 'worker',
onDone: 'finished',
},
},
finished: {
type: 'final',
output: {
res2: 2,
},
},
},
},
},
},
end: { type: 'final' },
},
})
const actor = createActor(machine).start()Question:
- Does XState v5 support automatic output aggregation for Parallel States?
- If yes, what am I missing?
- If no, is using
contextandassignthe only recommended way to collect results from parallel branches?
Thank you!
powfan
Metadata
Metadata
Assignees
Labels
No labels