-
Notifications
You must be signed in to change notification settings - Fork 134
/
Copy pathCollection.svelte
34 lines (29 loc) · 946 Bytes
/
Collection.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<script lang="ts" generics="Data extends DocumentData">
import type {
CollectionReference,
DocumentData,
Firestore,
Query,
} from "firebase/firestore";
import { collectionStore } from "../stores/firestore.js";
import { getFirebaseContext } from "../stores/sdk.js";
export let ref: string | CollectionReference<Data> | Query<Data>;
export let startWith: Data[] | undefined = undefined;
const { firestore } = getFirebaseContext();
let store = collectionStore<Data>(firestore!, ref, startWith);
interface $$Slots {
default: {
data: Data[];
error: Error | null;
ref: CollectionReference<Data[]> | Query<Data[]> | null;
count: number;
firestore?: Firestore;
};
loading: {};
}
</script>
{#if $store !== undefined}
<slot data={$store?.data} error={$store?.error} ref={store.ref} count={$store?.data?.length ?? 0} {firestore} />
{:else}
<slot name="loading" />
{/if}