From 80fdc4517408476c41a859075bba06b0f3bb075c Mon Sep 17 00:00:00 2001 From: Sirttas Date: Wed, 20 Sep 2023 23:06:39 +0200 Subject: [PATCH] fix subscription --- src/pages/market/Track.vue | 2 +- src/pocketbase/collection.ts | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/pages/market/Track.vue b/src/pages/market/Track.vue index 8a24726..1f8f177 100644 --- a/src/pages/market/Track.vue +++ b/src/pages/market/Track.vue @@ -21,7 +21,7 @@ watch(() => trackedItemStore.items.value, async itms => { return { ...i, ...price }; }); -}) +}, { immediate: true }) diff --git a/src/pocketbase/collection.ts b/src/pocketbase/collection.ts index 0b5b57d..c99c6fd 100644 --- a/src/pocketbase/collection.ts +++ b/src/pocketbase/collection.ts @@ -1,16 +1,12 @@ import { usePocketBase } from "@/pocketbase"; -import { RecordModel, RecordSubscription, UnsubscribeFunc } from "pocketbase"; -import { Ref, computed, onMounted, onUnmounted, ref } from "vue"; +import { RecordModel, RecordSubscription } from "pocketbase"; +import { Ref, computed, onMounted, ref } from "vue"; -export const watchCollection = (collection: string, query: string, callback: (data: RecordSubscription) => void) => { +export const watchCollection = (collection: string, topic: string, callback: (data: RecordSubscription) => void) => { const pb = usePocketBase(); - let unsubscribe: UnsubscribeFunc = () => Promise.resolve(); - onMounted(async () => { - unsubscribe = await pb.collection(collection).subscribe(query, callback); - }); - onUnmounted(() => unsubscribe()); + onMounted(async () => await pb.collection(collection).subscribe(topic, callback)); }; export const useCollection = (collection: string) => {