From b5fcece4a484c24a8d9195ae093baeae361d07bf Mon Sep 17 00:00:00 2001 From: rich Date: Mon, 19 Aug 2024 15:49:56 +0100 Subject: [PATCH] Add output to machine 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 --- server/machines/turn.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/server/machines/turn.ts b/server/machines/turn.ts index 1541bbef..0ed1044a 100644 --- a/server/machines/turn.ts +++ b/server/machines/turn.ts @@ -19,6 +19,8 @@ type Events = PlayerSubmitsAnswerEvent; type Input = { selectedQuestion: Question }; +type Output = { correctPlayerSocketIds: Player["socketId"][] }; + const dynamicParamFuncs = { addAnswer: ({ context, @@ -37,6 +39,7 @@ const turnMachine = setup({ context: Context; events: Events; input: Input; + output: Output; }, actions: { addAnswer: assign({ @@ -88,6 +91,9 @@ const turnMachine = setup({ ], }, }, + output: ({ context }) => ({ + correctPlayerSocketIds: context.correctPlayerSocketIds, + }), }); export { turnMachine };