Skip to content

Commit efff686

Browse files
authored
Fixed angular demo app issues related to newer versions of web SDK and wa-sqlite. (#442)
1 parent bd8c026 commit efff686

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

demos/angular-supabase-todolist/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,5 @@ testem.log
166166
# System files
167167
.DS_Store
168168
Thumbs.db
169+
170+
src/assets/@powersync

demos/angular-supabase-todolist/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ A step-by-step guide on Supabase<>PowerSync integration is available [here](http
1919
5. In a new terminal run `pnpm start` to start the server
2020
6. Go to <http://localhost:8080>
2121

22-
**Note:** The Angular development server (`pnpm serve`) doesn't support service worker applications
22+
### Notes
23+
24+
- The Angular development server (`pnpm serve`) doesn't support service worker applications
25+
- For Angular, workers need to be configured when instantiating `PowerSyncDatabase`. To do this, copy the worker assets (`pnpm powersync-web copy-assets -o src/assets` - done automatically in this demo for serving and building) and ensure the worker paths are specified ([example here](./src/app/powersync.service.ts)).
2326

2427
## Development Server
2528

demos/angular-supabase-todolist/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
"name": "angular-supabase-todolist",
33
"version": "0.0.25",
44
"scripts": {
5+
"copy-assets": "pnpm powersync-web copy-assets -o src/assets",
56
"ng": "ng",
6-
"serve": "ng serve",
7+
"serve": "pnpm copy-assets && ng serve",
78
"start": "http-server -p 8080 -c-1 dist/",
8-
"build": "ng build",
9+
"build": "pnpm copy-assets && ng build",
910
"format": "prettier --write .",
1011
"test:build": "pnpm build",
12+
"prewatch": "pnpm copy-assets",
1113
"watch": "ng build --watch --configuration development"
1214
},
1315
"private": true,

demos/angular-supabase-todolist/src/app/powersync.service.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import {
66
Index,
77
IndexedColumn,
88
PowerSyncBackendConnector,
9+
PowerSyncDatabase,
910
Schema,
1011
Table,
11-
WASQLitePowerSyncDatabaseOpenFactory
12+
WASQLiteOpenFactory
1213
} from '@powersync/web';
1314

1415
export interface ListRecord {
@@ -63,11 +64,21 @@ export class PowerSyncService {
6364
db: AbstractPowerSyncDatabase;
6465

6566
constructor() {
66-
const PowerSyncFactory = new WASQLitePowerSyncDatabaseOpenFactory({
67+
const factory = new WASQLiteOpenFactory({
68+
dbFilename: 'test.db',
69+
70+
// Specify the path to the worker script
71+
worker: 'assets/@powersync/worker/WASQLiteDB.umd.js'
72+
});
73+
74+
this.db = new PowerSyncDatabase({
6775
schema: AppSchema,
68-
dbFilename: 'test.db'
76+
database: factory,
77+
sync: {
78+
// Specify the path to the worker script
79+
worker: 'assets/@powersync/worker/SharedSyncImplementation.umd.js'
80+
}
6981
});
70-
this.db = PowerSyncFactory.getInstance();
7182
}
7283

7384
setupPowerSync = async (connector: PowerSyncBackendConnector) => {

0 commit comments

Comments
 (0)