Skip to content

Commit 3807514

Browse files
committed
Add support for Sync Streams in Vue and Nuxt modules with auto-imports. Update README and example usage for better clarity. Remove outdated README file from Nuxt package.
1 parent 20c1163 commit 3807514

6 files changed

Lines changed: 136 additions & 466 deletions

File tree

.changeset/friendly-points-ring.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,47 @@
11
---
2-
'@powersync/nuxt': minor
32
'@powersync/vue': minor
43
---
54

6-
Add support for Sync Streams for Vue and Nuxt
5+
Add support for Sync Streams for Vue
6+
7+
Subscribing to a sync stream and using its status:
8+
9+
```
10+
<script setup>
11+
import { useSyncStream } from '@powersync/vue';
12+
13+
14+
const { status } = useSyncStream('my-stream', { parameters: { userId: 'user-123' } });
15+
16+
// both the name and parameters can be reactive
17+
const streamName = ref('my-stream')
18+
const streamOptions = ref({ parameters: { userId: 'user-123' } })
19+
20+
useSyncStream(streamName, streamOptions);
21+
</script>
22+
23+
<template>
24+
<div v-if="status">
25+
<span v-if="status.hasSynced">Stream synced</span>
26+
<span v-else>Syncing...</span>
27+
</div>
28+
</template>
29+
```
30+
31+
Running a query backed by sync streams:
32+
33+
```
34+
<script setup>
35+
import { useQuery } from '@powersync/vue';
36+
37+
// Subscribe to streams; query runs immediately
38+
const { data } = useQuery('SELECT * FROM lists', [], {
39+
streams: [{ name: 'lists-stream' }]
40+
});
41+
42+
// Or wait for the stream to sync before showing results
43+
const { data: lists, isLoading } = useQuery('SELECT * FROM lists', [], {
44+
streams: [{ name: 'lists-stream', waitForStream: true }]
45+
});
46+
</script>
47+
```

.changeset/light-dingos-stare.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
'@powersync/nuxt': minor
3+
---
4+
5+
Expose Sync Streams comosable to use in Nuxt with auto-imports
6+
7+
Example:
8+
9+
```
10+
<script setup lang="ts">
11+
// useSyncStream is auto-imported in Nuxt
12+
const streamName = ref('my-stream');
13+
const { status } = useSyncStream(streamName, { parameters: { id: 'abc' } });
14+
</script>
15+
16+
<template>
17+
<div v-if="status?.hasSynced">Stream ready</div>
18+
<div v-else>Syncing...</div>
19+
</template>
20+
```

0 commit comments

Comments
 (0)