From 68407152221d50372e5394cda32123608b3d5bb1 Mon Sep 17 00:00:00 2001 From: Junyao Chen Date: Fri, 25 Aug 2023 23:06:35 -0400 Subject: [PATCH] poll_data: Define outbound data types for each message type. This commit introduces specific outbound data types for each message type for reusability. For example, `poll_widget.ts` reuses these types. --- web/shared/src/poll_data.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/web/shared/src/poll_data.ts b/web/shared/src/poll_data.ts index 13568f188e..b04c0207ab 100644 --- a/web/shared/src/poll_data.ts +++ b/web/shared/src/poll_data.ts @@ -31,7 +31,9 @@ export type WidgetData = { }; export type InboundData = Record & {type: string}; - +export type NewOptionOutboundData = {type: string; idx: number; option: string}; +export type QuestionOutboundData = {type: string; question: string}; +export type VoteOutboundData = {type: string; key: string; vote: number}; export type PollHandle = { // Add generic key property to allow string indexing on PollHandle type in `handle_event` method. [key: string]: { @@ -39,15 +41,15 @@ export type PollHandle = { inbound: (sender_id: number, data: InboundData) => void; }; new_option: { - outbound: (option: string) => {type: string; idx: number; option: string}; + outbound: (option: string) => NewOptionOutboundData; inbound: (sender_id: number | string, data: InboundData) => void; }; question: { - outbound: (question: string) => {type: string; question: string} | undefined; + outbound: (question: string) => QuestionOutboundData | undefined; inbound: (sender_id: number, data: InboundData) => void; }; vote: { - outbound: (key: string) => {type: string; key: string; vote: number}; + outbound: (key: string) => VoteOutboundData; inbound: (sender_id: number, data: InboundData) => void; }; };