From 06c1a471368698265ddf7d67430aef6b879a5d21 Mon Sep 17 00:00:00 2001 From: Mike Christensen Date: Thu, 9 May 2024 14:35:55 +0100 Subject: [PATCH] example: fix livesync merge function types --- examples/livesync/components/Drawer/actions.ts | 8 ++++++-- .../livesync/components/modelsClient/useCommentsModel.ts | 2 -- .../livesync/components/modelsClient/useIssueModel.ts | 1 - 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/livesync/components/Drawer/actions.ts b/examples/livesync/components/Drawer/actions.ts index c69bae1..d715c27 100644 --- a/examples/livesync/components/Drawer/actions.ts +++ b/examples/livesync/components/Drawer/actions.ts @@ -46,7 +46,7 @@ export const fetchIssueById = async (id: number) => { export const fetchComments = async (id: number) => { const data = await sql.begin(async (sql) => { - const comments = await sql` + const result = await sql` SELECT c.id, c.content, c.updated_at, u.last_name, u.first_name, u.color FROM comments c @@ -54,9 +54,13 @@ export const fetchComments = async (id: number) => { ON u.id = c.user_id WHERE issue_id = ${id} ORDER BY c.updated_at DESC - `; + `.cursor(); const ids = await sql`SELECT COALESCE(MAX(sequence_id), 0) FROM outbox`; + let comments: CommentData[] = []; + for await (const [row] of result) { + comments.push(row); + } return { data: comments, sequenceId: ids[0].coalesce }; }); diff --git a/examples/livesync/components/modelsClient/useCommentsModel.ts b/examples/livesync/components/modelsClient/useCommentsModel.ts index 2f408b4..997199a 100644 --- a/examples/livesync/components/modelsClient/useCommentsModel.ts +++ b/examples/livesync/components/modelsClient/useCommentsModel.ts @@ -20,10 +20,8 @@ export const useCommentsModel = (issueId: number | null): [CommentData[] | undef if (!issueId) return; const model = modelsClient().models.get({ - name: `comments:${issueId}`, channelName: `comments:${issueId}`, sync: fetchComments, - // @ts-ignore - types to be fixed for merge functions later in COL-651 https://ably.atlassian.net/browse/COL-651 merge, }); diff --git a/examples/livesync/components/modelsClient/useIssueModel.ts b/examples/livesync/components/modelsClient/useIssueModel.ts index 7ce863a..9091204 100644 --- a/examples/livesync/components/modelsClient/useIssueModel.ts +++ b/examples/livesync/components/modelsClient/useIssueModel.ts @@ -23,7 +23,6 @@ export const useIssueModel = (issueId: number | null): [IssueType | undefined, M const model: ModelType = modelsClient().models.get({ channelName: `issue:${issueId}`, sync: fetchIssueById, - // @ts-ignore - types to be fixed for merge functions later in COL-651 https://ably.atlassian.net/browse/COL-651 merge, });