Skip to content

Commit

Permalink
Add output to machine
Browse files Browse the repository at this point in the history
This is the correct way to output data from a machine when it reaches
its final state.
See docs: https://stately.ai/docs/final-states#output
  • Loading branch information
rich committed Aug 19, 2024
1 parent 11e9e1c commit b5fcece
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions server/machines/turn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type Events = PlayerSubmitsAnswerEvent;

type Input = { selectedQuestion: Question };

type Output = { correctPlayerSocketIds: Player["socketId"][] };

const dynamicParamFuncs = {
addAnswer: ({
context,
Expand All @@ -37,6 +39,7 @@ const turnMachine = setup({
context: Context;
events: Events;
input: Input;
output: Output;
},
actions: {
addAnswer: assign({
Expand Down Expand Up @@ -88,6 +91,9 @@ const turnMachine = setup({
],
},
},
output: ({ context }) => ({
correctPlayerSocketIds: context.correctPlayerSocketIds,
}),
});

export { turnMachine };

0 comments on commit b5fcece

Please sign in to comment.