-
Notifications
You must be signed in to change notification settings - Fork 134
/
Copy pathDoc.svelte
35 lines (30 loc) · 903 Bytes
/
Doc.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
35
<script lang="ts" generics="Data extends DocumentData">
import type {
DocumentData,
DocumentReference,
Firestore,
} from "firebase/firestore";
import { docStore } from "../stores/firestore.js";
import { getFirebaseContext } from "../stores/sdk.js";
export let ref: string | DocumentReference<Data>;
export let startWith: Data | undefined = undefined;
const { firestore } = getFirebaseContext();
let store = docStore(firestore!, ref, startWith);
let state = store.stateStore;
interface $$Slots {
default: {
data: Data;
ref: DocumentReference<Data> | null;
firestore?: Firestore;
};
loading: {};
notExist: {};
}
</script>
{#if $state.loading}
<slot name="loading" />
{:else if !$state.exists}
<slot name="notExist" />
{:else if $store !== undefined && $store !== null}
<slot data={$store} ref={store.ref} {firestore} />
{/if}