Skip to content

Commit

Permalink
example: fix livesync merge function types
Browse files Browse the repository at this point in the history
  • Loading branch information
mschristensen committed May 10, 2024
1 parent 418e9c4 commit 06c1a47
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
8 changes: 6 additions & 2 deletions examples/livesync/components/Drawer/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,21 @@ export const fetchIssueById = async (id: number) => {

export const fetchComments = async (id: number) => {
const data = await sql.begin(async (sql) => {
const comments = await sql<CommentData[]>`
const result = await sql<CommentData[]>`
SELECT
c.id, c.content, c.updated_at, u.last_name, u.first_name, u.color
FROM comments c
LEFT OUTER JOIN users u
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 };
});
Expand Down
2 changes: 0 additions & 2 deletions examples/livesync/components/modelsClient/useCommentsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand Down
1 change: 0 additions & 1 deletion examples/livesync/components/modelsClient/useIssueModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand Down

0 comments on commit 06c1a47

Please sign in to comment.