Skip to content

Commit b060725

Browse files
committed
Adopt priorities in example app
1 parent 4ebad73 commit b060725

File tree

5 files changed

+42
-10
lines changed

5 files changed

+42
-10
lines changed

demos/supabase-todolist/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,25 @@ Create a new PowerSync instance, connecting to the database of the Supabase proj
2929

3030
Then deploy the following sync rules:
3131

32+
```yaml
33+
bucket_definitions:
34+
user_lists:
35+
priority: 1
36+
parameters: select id as list_id from lists where owner_id = request.user_id()
37+
data:
38+
- select * from lists where id = bucket.list_id
39+
40+
user_todos:
41+
parameters: select id as list_id from lists where owner_id = request.user_id()
42+
data:
43+
- select * from todos where list_id = bucket.list_id
44+
```
45+
46+
The rules synchronize list with a higher priority the items within the list. This can be
47+
useful to keep the list overview page reactive during a large sync cycle affecting many
48+
rows in the `user_todos` bucket. The two buckets can also be unified into a single one if
49+
priorities are not important (the app will work without changes):
50+
3251
```yaml
3352
bucket_definitions:
3453
user_lists:

demos/supabase-todolist/lib/widgets/lists_page.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:async';
22

33
import 'package:flutter/material.dart';
4+
import 'package:powersync/powersync.dart';
45

56
import './list_item.dart';
67
import './list_item_dialog.dart';
@@ -51,6 +52,8 @@ class ListsWidget extends StatefulWidget {
5152
}
5253

5354
class _ListsWidgetState extends State<ListsWidget> {
55+
static final _listsPriority = BucketPriority(1);
56+
5457
List<TodoList> _data = [];
5558
bool hasSynced = false;
5659
StreamSubscription? _subscription;
@@ -75,7 +78,7 @@ class _ListsWidgetState extends State<ListsWidget> {
7578
return;
7679
}
7780
setState(() {
78-
hasSynced = status.hasSynced ?? false;
81+
hasSynced = status.statusForPriority(_listsPriority).hasSynced ?? false;
7982
});
8083
});
8184
}

demos/supabase-todolist/lib/widgets/todo_list_page.dart

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,20 @@ class TodoListWidgetState extends State<TodoListWidget> {
7979

8080
@override
8181
Widget build(BuildContext context) {
82-
return ListView(
83-
padding: const EdgeInsets.symmetric(vertical: 8.0),
84-
children: _data.map((todo) {
85-
return TodoItemWidget(todo: todo);
86-
}).toList(),
82+
return StreamBuilder(
83+
stream: TodoList.watchSyncStatus().map((e) => e.hasSynced),
84+
builder: (context, snapshot) {
85+
if (snapshot.data ?? false) {
86+
return const Text('Busy with sync');
87+
}
88+
89+
return ListView(
90+
padding: const EdgeInsets.symmetric(vertical: 8.0),
91+
children: _data.map((todo) {
92+
return TodoItemWidget(todo: todo);
93+
}).toList(),
94+
);
95+
},
8796
);
8897
}
8998
}

demos/supabase-todolist/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
ignoresPersistentStateOnLaunch = "NO"
6060
debugDocumentVersioning = "YES"
6161
debugServiceExtension = "internal"
62+
enableGPUValidationMode = "1"
6263
allowLocationSimulation = "YES">
6364
<BuildableProductRunnable
6465
runnableDebuggingMode = "0">

demos/supabase-todolist/pubspec.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -478,28 +478,28 @@ packages:
478478
path: "../../packages/powersync"
479479
relative: true
480480
source: path
481-
version: "1.11.2"
481+
version: "1.11.3"
482482
powersync_attachments_helper:
483483
dependency: "direct main"
484484
description:
485485
path: "../../packages/powersync_attachments_helper"
486486
relative: true
487487
source: path
488-
version: "0.6.18"
488+
version: "0.6.18+1"
489489
powersync_core:
490490
dependency: "direct overridden"
491491
description:
492492
path: "../../packages/powersync_core"
493493
relative: true
494494
source: path
495-
version: "1.1.2"
495+
version: "1.1.3"
496496
powersync_flutter_libs:
497497
dependency: "direct overridden"
498498
description:
499499
path: "../../packages/powersync_flutter_libs"
500500
relative: true
501501
source: path
502-
version: "0.4.4"
502+
version: "0.4.5"
503503
pub_semver:
504504
dependency: transitive
505505
description:

0 commit comments

Comments
 (0)