11<script >
2- export let path;
3- export let query = null ;
4- export let traceId = ' ' ;
5- export let log = false ;
6- export let startWith = undefined ;
7- export let maxWait = 10000 ;
8- import { onMount , onDestroy , createEventDispatcher } from ' svelte' ;
9-
10- import { collectionStore } from ' ./firestore' ;
11-
12- const store = collectionStore (path, query, { startWith, traceId, log, maxWait });
13-
14- const dispatch = createEventDispatcher ();
15-
16- let unsub;
17-
18- onMount (() => {
19- dispatch (' ref' , { ref: store .ref });
20-
21- unsub = store .subscribe (data => {
22- dispatch (' data' , {
23- data
24- });
25- });
2+ export let path;
3+ export let query = null ;
4+ export let traceId = " " ;
5+ export let log = false ;
6+ export let startWith = undefined ;
7+ export let maxWait = 10000 ;
8+
9+ import { onDestroy , createEventDispatcher } from " svelte" ;
10+
11+ import { collectionStore } from " ./firestore" ;
12+
13+ let store = collectionStore (path, query, {
14+ startWith,
15+ traceId,
16+ log,
17+ maxWait
18+ });
19+
20+ const dispatch = createEventDispatcher ();
21+
22+ let unsub;
23+
24+ // Props changed
25+ $: {
26+ if (unsub) {
27+ unsub ();
28+ store = collectionStore (path, query, {
29+ startWith,
30+ traceId,
31+ log,
32+ maxWait
33+ });
34+ }
35+
36+ dispatch (" ref" , { ref: store .ref });
37+
38+ unsub = store .subscribe (data => {
39+ dispatch (" data" , {
40+ data
41+ });
2642 });
43+ }
2744
28- onDestroy (() => unsub ());
29-
30-
45+ onDestroy (() => unsub ());
3146 </script >
3247
33-
3448{#if $store }
35- <slot data ={$store } ref ={store .ref } error ={store .error }></ slot >
49+ <slot data ={$store } ref ={store .ref } error ={store .error } / >
3650{:else if store .loading }
37- <slot name =" loading" ></ slot >
51+ <slot name =" loading" / >
3852{:else }
39- <slot name =" fallback" ></ slot >
40- {/if }
53+ <slot name =" fallback" / >
54+ {/if }
0 commit comments