File tree Expand file tree Collapse file tree 5 files changed +19
-11
lines changed Expand file tree Collapse file tree 5 files changed +19
-11
lines changed Original file line number Diff line number Diff line change @@ -208,10 +208,12 @@ data.subscribe(v => doStuff(v) )
208
208
209
209
### Firebase App Context
210
210
211
- The Firebase SDK is available via the [ Context API] ( https://svelte.dev/tutorial/context-api ) under the key of ` firebase ` .
211
+ The Firebase SDK is available via the [ Context API] ( https://svelte.dev/tutorial/context-api ) under the key of ` firebase ` using the ` getFirebase ` function .
212
212
213
213
``` js
214
- const db = getContext (' firebase' ).firestore ();
214
+ const app = getContext (' firebase' ).getFirebase ();
215
+ const db = app .firestore ();
216
+ const auth = app .auth ();
215
217
```
216
218
217
219
## API
Original file line number Diff line number Diff line change 1
1
{
2
- "version" : " 0.1.4 " ,
2
+ "version" : " 0.1.5 " ,
3
3
"name" : " sveltefire" ,
4
4
"svelte" : " src/index.js" ,
5
5
"main" : " dist/index.js" ,
Original file line number Diff line number Diff line change 11
11
// Emit firebase
12
12
const dispatch = createEventDispatcher ();
13
13
14
- // Set firebase context
15
- firebase = firebase || window .firebase ;
16
- setContext (" firebase" , firebase);
14
+ // Must be a function to ensure changes after initialization are caught
15
+ setContext (" firebase" , {
16
+ getFirebase : () => firebase
17
+ });
18
+
17
19
18
20
onMount (() => {
21
+
22
+ // Set firebase context from window if needed
23
+ firebase = firebase || (window && window .firebase );
24
+
19
25
if (! firebase) {
20
26
throw Error (
21
27
" No firebase app was provided. You must provide an initialized Firebase app or make it available globally."
Original file line number Diff line number Diff line change 1
1
import { getContext } from 'svelte' ;
2
2
3
-
4
- export function getApp ( ) {
5
- return getContext ( 'firebase' ) ;
3
+ export function getFirebaseContext ( ) {
4
+ const { getFirebase } = getContext ( 'firebase' ) ;
5
+ return getFirebase ( ) ;
6
6
}
7
7
8
8
// Validates end-user has setup context and imported proper modules into the Svelte app
9
9
export function assertApp ( pkg ) {
10
10
11
- const app = getApp ( ) ;
11
+ const app = getFirebaseContext ( ) ;
12
12
13
13
if ( ! app ) {
14
14
throw new Error ( `Missing Firebase app in context. Are you inside a 'FirebaseApp' component?` )
You can’t perform that action at this time.
0 commit comments