Skip to content

Commit 3c421ea

Browse files
DominicGBauerDominicGBauer
andauthored
chore(common): improve hasSynced (#163)
Co-authored-by: DominicGBauer <[email protected]>
1 parent 893e88c commit 3c421ea

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

.changeset/unlucky-hats-cover.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@powersync/common": patch
3+
---
4+
5+
Fix hasSynced to change when there is no data on app load

packages/common/src/client/AbstractPowerSyncDatabase.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,10 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
325325
this.syncStreamImplementation = this.generateSyncStreamImplementation(connector);
326326
this.syncStatusListenerDisposer = this.syncStreamImplementation.registerListener({
327327
statusChanged: (status) => {
328-
this.currentStatus = new SyncStatus({ ...status.toJSON(), hasSynced: this.currentStatus?.hasSynced });
328+
this.currentStatus = new SyncStatus({
329+
...status.toJSON(),
330+
hasSynced: this.currentStatus?.hasSynced || !!status.lastSyncedAt
331+
});
329332
this.iterateListeners((cb) => cb.statusChanged?.(this.currentStatus));
330333
}
331334
});
@@ -766,7 +769,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
766769
`SELECT DISTINCT tbl_name FROM sqlite_master WHERE rootpage IN (SELECT json_each.value FROM json_each(?))`,
767770
[JSON.stringify(rootPages)]
768771
);
769-
for (let table of tables) {
772+
for (const table of tables) {
770773
resolvedTables.push(table.tbl_name.replace(POWERSYNC_TABLE_MATCH, ''));
771774
}
772775
}
@@ -937,7 +940,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
937940
? filteredTables
938941
: filteredTables.map((t) => t.replace(POWERSYNC_TABLE_MATCH, ''));
939942

940-
for (let table of mappedTableNames) {
943+
for (const table of mappedTableNames) {
941944
changedTables.add(table);
942945
}
943946
}

0 commit comments

Comments
 (0)