@tthr/vue 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -180,13 +180,15 @@ export function useMutation<TArgs, TResult>(
180
180
  export function useTetherSubscription(
181
181
  queryName: string,
182
182
  args: Record<string, unknown> | undefined,
183
- onUpdate: () => void
183
+ onUpdate: (data?: unknown) => void
184
184
  ): { isConnected: Ref<boolean> } {
185
185
  const isConnected = ref(false);
186
186
 
187
187
  if (import.meta.client) {
188
188
  let ws: WebSocket | null = null;
189
189
  let reconnectTimeout: ReturnType<typeof setTimeout> | null = null;
190
+ // Generate a unique subscription ID
191
+ const subscriptionId = `${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
190
192
 
191
193
  const connect = () => {
192
194
  // Get config from window (set by plugin)
@@ -200,20 +202,25 @@ export function useTetherSubscription(
200
202
  ws = new WebSocket(wsUrl);
201
203
 
202
204
  ws.onopen = () => {
203
- isConnected.value = true;
204
- // Subscribe to the query
205
- ws?.send(JSON.stringify({
206
- type: 'subscribe',
207
- query: queryName,
208
- args,
209
- }));
205
+ // Wait for connected message before subscribing
210
206
  };
211
207
 
212
208
  ws.onmessage = (event) => {
213
209
  try {
214
210
  const message = JSON.parse(event.data);
215
- if (message.type === 'update' && message.query === queryName) {
216
- onUpdate();
211
+
212
+ if (message.type === 'connected') {
213
+ isConnected.value = true;
214
+ // Subscribe to the query with our ID
215
+ ws?.send(JSON.stringify({
216
+ type: 'subscribe',
217
+ id: subscriptionId,
218
+ query: queryName,
219
+ args,
220
+ }));
221
+ } else if (message.type === 'data' && message.id === subscriptionId) {
222
+ // Call onUpdate with the fresh data
223
+ onUpdate(message.data);
217
224
  }
218
225
  } catch {
219
226
  // Ignore parse errors
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tthr/vue",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "Tether Vue/Nuxt SDK",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",