svelte-firekit 0.1.4 → 0.1.5

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.
@@ -57,7 +57,7 @@
57
57
  count: startWith?.length ?? 0
58
58
  });
59
59
 
60
- // Subscribe to collection changes only if in browser and collection service exists
60
+ // Initialize Firestore and collection service
61
61
  $effect(() => {
62
62
  if (!browser) {
63
63
  collectionState = {
@@ -69,7 +69,7 @@
69
69
  return;
70
70
  }
71
71
 
72
- // Initialize Firestore and collection service
72
+ // Initialize Firestore
73
73
  firestore = firebaseService.getDbInstance();
74
74
  if (!firestore) {
75
75
  collectionState = {
@@ -86,18 +86,8 @@
86
86
  typeof ref === 'string' ? collection(firestore, ref) : (ref as CollectionReference | Query);
87
87
 
88
88
  // Create collection service
89
- collectionService = firekitCollection(
90
- typeof ref === 'string' ? ref : (ref as CollectionReference).path,
91
- queryConstraints
92
- );
93
-
94
- // Update state based on collection service state
95
- collectionState = {
96
- loading: collectionService.loading,
97
- data: collectionService.data,
98
- error: collectionService.error,
99
- count: collectionService.size
100
- };
89
+ const path = typeof ref === 'string' ? ref : (ref as CollectionReference).path;
90
+ collectionService = firekitCollection(path, queryConstraints);
101
91
 
102
92
  // Set up event listener for real-time updates
103
93
  const unsubscribe = collectionService.addEventListener((event) => {
@@ -128,6 +118,14 @@
128
118
  }
129
119
  });
130
120
 
121
+ // Set initial state from service
122
+ collectionState = {
123
+ loading: collectionService.loading,
124
+ data: collectionService.data,
125
+ error: collectionService.error,
126
+ count: collectionService.size
127
+ };
128
+
131
129
  return () => {
132
130
  unsubscribe();
133
131
  collectionService?.dispose();
@@ -45,48 +45,21 @@
45
45
  let docRef: DocumentReference | null = $state(null);
46
46
  let documentService: any = $state(null);
47
47
 
48
- // Reactive document state
49
- let componentState = $state({
50
- loading: true,
51
- data: null as DocumentData | null,
52
- error: null as Error | null,
53
- exists: false
54
- });
55
-
56
- // Initialize in browser environment
48
+ // Initialize document service
57
49
  $effect(() => {
58
50
  if (!browser) return;
59
51
 
60
52
  firestore = firebaseService.getDbInstance();
61
- if (!firestore) {
62
- throw new Error('Firestore instance not available');
63
- }
53
+ if (!firestore) return;
64
54
 
65
55
  // Create document reference if path string is provided
66
56
  docRef = typeof ref === 'string' ? doc(firestore, ref) : ref;
67
57
 
68
58
  // Create document service
69
59
  documentService = firekitDoc(docRef.path, startWith ?? undefined, options);
70
- });
71
-
72
- // Subscribe to document changes only if in browser and document service exists
73
- $effect(() => {
74
- if (!browser || !documentService) {
75
- componentState = {
76
- loading: false,
77
- data: startWith ?? null,
78
- error: null,
79
- exists: !!startWith
80
- };
81
- return;
82
- }
83
60
 
84
- // Update component state based on document service state
85
- componentState = {
86
- loading: documentService.loading,
87
- data: documentService.data,
88
- error: documentService.error,
89
- exists: documentService.exists
61
+ return () => {
62
+ documentService?.dispose();
90
63
  };
91
64
  });
92
65
 
@@ -100,7 +73,25 @@
100
73
 
101
74
  {#if !browser}
102
75
  {@render children(startWith ?? null, null as any, null as any)}
103
- {:else if componentState.loading}
76
+ {:else if !firestore}
77
+ <div class="flex items-center justify-center min-h-screen">
78
+ <div class="text-center">
79
+ <div class="text-red-500 text-lg font-semibold mb-2">Firestore Not Available</div>
80
+ <p class="text-gray-600">Firestore instance is not available.</p>
81
+ </div>
82
+ </div>
83
+ {:else if !documentService}
84
+ {#if loading}
85
+ {@render loading()}
86
+ {:else}
87
+ <div class="flex items-center justify-center min-h-screen">
88
+ <div class="text-center">
89
+ <div class="animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900 mx-auto"></div>
90
+ <p class="mt-2 text-gray-600">Initializing document...</p>
91
+ </div>
92
+ </div>
93
+ {/if}
94
+ {:else if documentService.loading}
104
95
  {#if loading}
105
96
  {@render loading()}
106
97
  {:else}
@@ -111,15 +102,15 @@
111
102
  </div>
112
103
  </div>
113
104
  {/if}
114
- {:else if componentState.error}
105
+ {:else if documentService.error}
115
106
  <div class="flex items-center justify-center min-h-screen">
116
107
  <div class="text-center">
117
108
  <div class="text-red-500 text-lg font-semibold mb-2">Error Loading Document</div>
118
- <p class="text-gray-600 mb-4">{componentState.error.message}</p>
119
- {#if documentService?.canRefresh}
109
+ <p class="text-gray-600 mb-4">{documentService.error.message}</p>
110
+ {#if documentService.canRefresh}
120
111
  <button
121
112
  class="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600"
122
- onclick={() => documentService?.refresh()}
113
+ onclick={() => documentService.refresh()}
123
114
  >
124
115
  Retry
125
116
  </button>
@@ -127,5 +118,5 @@
127
118
  </div>
128
119
  </div>
129
120
  {:else}
130
- {@render children(componentState.data ?? null, docRef!, firestore!)}
121
+ {@render children(documentService.data ?? null, docRef!, firestore!)}
131
122
  {/if}
@@ -23,6 +23,6 @@ type $$ComponentProps = {
23
23
  */
24
24
  options?: DocumentOptions;
25
25
  };
26
- declare const Ddoc: import("svelte").Component<$$ComponentProps, {}, "">;
27
- type Ddoc = ReturnType<typeof Ddoc>;
28
- export default Ddoc;
26
+ declare const Doc: import("svelte").Component<$$ComponentProps, {}, "">;
27
+ type Doc = ReturnType<typeof Doc>;
28
+ export default Doc;
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import { ref, type StorageReference, type UploadTaskSnapshot } from 'firebase/storage';
2
+ import { type UploadTaskSnapshot } from 'firebase/storage';
3
3
  import { firebaseService } from '../firebase.js';
4
4
  import { firekitUploadTask } from '../services/storage.svelte.js';
5
5
  import { browser } from '$app/environment';
package/dist/index.d.ts CHANGED
@@ -14,7 +14,7 @@ export { default as AuthGuard } from './components/auth-guard.svelte';
14
14
  export { default as CustomGuard } from './components/custom-guard.svelte';
15
15
  export { default as SignedIn } from './components/signed-in.svelte';
16
16
  export { default as SignedOut } from './components/signed-out.svelte';
17
- export { default as Doc } from './components/Ddoc.svelte';
17
+ export { default as Doc } from './components/Doc.svelte';
18
18
  export { default as Collection } from './components/Collection.svelte';
19
19
  export { default as Node } from './components/Node.svelte';
20
20
  export { default as NodeList } from './components/node-list.svelte';
package/dist/index.js CHANGED
@@ -23,7 +23,7 @@ export { default as AuthGuard } from './components/auth-guard.svelte';
23
23
  export { default as CustomGuard } from './components/custom-guard.svelte';
24
24
  export { default as SignedIn } from './components/signed-in.svelte';
25
25
  export { default as SignedOut } from './components/signed-out.svelte';
26
- export { default as Doc } from './components/Ddoc.svelte';
26
+ export { default as Doc } from './components/Doc.svelte';
27
27
  export { default as Collection } from './components/Collection.svelte';
28
28
  export { default as Node } from './components/Node.svelte';
29
29
  export { default as NodeList } from './components/node-list.svelte';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-firekit",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "license": "MIT",
5
5
  "scripts": {
6
6
  "dev": "vite dev",