Skip to content

Commit 1bb56be

Browse files
Christiaan LandmanChristiaan Landman
authored andcommitted
chore: renamed attachmentIds to onAttachmentIdsChange, to match changed signature
1 parent d223454 commit 1bb56be

File tree

5 files changed

+14
-17
lines changed

5 files changed

+14
-17
lines changed

.changeset/heavy-dogs-work.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"powersync-example": minor
33
---
44

5-
Updated implementation of attachmentIds in PhotoAttachmentQueue to match updated abstract signature from AbstractAttachmentQueue.
5+
Updated/renamed implementation of `attachmentIds` to `onAttachmentIdsChange`, now implements a callback approach instead of AsyncGenerator.

.changeset/slow-years-pull.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"@journeyapps/powersync-attachments": major
33
---
44

5-
Changed abstract attachmentIds member of AbstractAttachmentQueue to use callback instead of an AsyncGenerator.
5+
Renamed abstract `attachmentIds` to `onAttachmentIdsChange` in `AbstractAttachmentQueue`, changed to use callback signature instead of an AsyncGenerator.

demos/react-native-supabase-todolist/library/powersync/PhotoAttachmentQueue.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ export class PhotoAttachmentQueue extends AbstractAttachmentQueue {
1616
await super.init();
1717
}
1818

19-
attachmentIds(onResult: (ids: string[]) => void): void {
19+
onAttachmentIdsChange(onUpdate: (ids: string[]) => void): void {
2020
this.powersync.watch(`SELECT photo_id as id FROM ${TODO_TABLE} WHERE photo_id IS NOT NULL`, [], {
21-
onResult: result => onResult(result.rows?._array.map((r) => r.id) ?? [])
21+
onResult: result => onUpdate(result.rows?._array.map((r) => r.id) ?? [])
2222
});
2323
}
2424

packages/powersync-attachments/README.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,18 @@ import { AbstractAttachmentQueue } from '@journeyapps/powersync-attachments';
6363
export class AttachmentQueue extends AbstractAttachmentQueue {}
6464
```
6565

66-
2. Implement `attachmentIds`, an `AsyncIterator` method to return an array of `string` values of IDs that relate to attachments in your app. We recommend using `PowerSync`'s `watch` query to return the all IDs of attachments in your app.
66+
2. Implement `onAttachmentIdsChange`, which takes in a callback to handle an array of `string` values of IDs that relate to attachments in your app. We recommend using `PowerSync`'s `watch` query to return the all IDs of attachments in your app.
6767

6868
In this example, we query all photos that have been captured as part of an inspection and map these to an array of `string` values.
6969

7070
```javascript
7171
import { AbstractAttachmentQueue } from '@journeyapps/powersync-attachments';
7272

7373
export class AttachmentQueue extends AbstractAttachmentQueue {
74-
async *attachmentIds() {
75-
for await (const result of this.powersync.watch(
76-
`SELECT photo_id as id FROM checklists WHERE photo_id IS NOT NULL`,
77-
[]
78-
)) {
79-
yield result.rows?._array.map((r) => r.id) ?? [];
80-
}
74+
onAttachmentIdsChange(onUpdate) {
75+
this.powersync.watch('SELECT photo_id as id FROM checklists WHERE photo_id IS NOT NULL', [], {
76+
onResult: result => onUpdate(result.rows?._array.map((r) => r.id) ?? [])
77+
});
8178
}
8279
}
8380
```

packages/powersync-attachments/src/AbstractAttachmentQueue.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ export abstract class AbstractAttachmentQueue<T extends AttachmentQueueOptions =
6262
*
6363
* @example
6464
* ```typescript
65-
* attachmentIds(onResult: (ids: string[]) => void): void {
65+
* onAttachmentIdsChange(onUpdate) {
6666
* this.powersync.watch('SELECT photo_id as id FROM todos WHERE photo_id IS NOT NULL', [], {
67-
* onResult: result => onResult(result.rows?._array.map((r) => r.id) ?? [])
67+
* onResult: result => onUpdate(result.rows?._array.map((r) => r.id) ?? [])
6868
* });
6969
* }
70-
*
70+
* ```
7171
*/
72-
abstract attachmentIds(onResult: (ids: string[]) => void): void;
72+
abstract onAttachmentIdsChange(onUpdate: (ids: string[]) => void): void;
7373

7474

7575
/**
@@ -111,7 +111,7 @@ export abstract class AbstractAttachmentQueue<T extends AttachmentQueueOptions =
111111
}
112112

113113
async watchAttachmentIds() {
114-
this.attachmentIds(async (ids) => {
114+
this.onAttachmentIdsChange(async (ids) => {
115115
const _ids = `${ids.map((id) => `'${id}'`).join(',')}`;
116116
console.debug(`Queuing for sync, attachment IDs: [${_ids}]`);
117117

0 commit comments

Comments
 (0)