@@ -34,34 +34,24 @@ function importSDK(sdk: ComponentName) {
3434 case 'messaging' :
3535 return import ( /* webpackChunkName: "messaging" */ 'firebase/messaging' ) ;
3636 case 'performance' :
37- return import (
38- /* webpackChunkName: "performance" */ 'firebase/performance'
39- ) ;
37+ return import ( /* webpackChunkName: "performance" */ 'firebase/performance' ) ;
4038 case 'remoteConfig' :
41- return import (
42- /* webpackChunkName: "remoteConfig" */ 'firebase/remote-config'
43- ) ;
39+ return import ( /* webpackChunkName: "remoteConfig" */ 'firebase/remote-config' ) ;
4440 case 'storage' :
4541 return import ( /* webpackChunkName: "storage" */ 'firebase/storage' ) ;
4642 }
4743}
4844
49- function proxyComponent ( componentName : 'auth' ) : typeof firebase . auth ;
50- function proxyComponent ( componentName : 'analytics' ) : typeof firebase . analytics ;
51- function proxyComponent ( componentName : 'database' ) : typeof firebase . database ;
52- function proxyComponent ( componentName : 'firestore' ) : typeof firebase . firestore ;
53- function proxyComponent ( componentName : 'functions' ) : typeof firebase . functions ;
54- function proxyComponent ( componentName : 'messaging' ) : typeof firebase . messaging ;
55- function proxyComponent (
56- componentName : 'performance'
57- ) : typeof firebase . performance ;
58- function proxyComponent (
59- componentName : 'remoteConfig'
60- ) : typeof firebase . remoteConfig ;
61- function proxyComponent ( componentName : 'storage' ) : typeof firebase . storage ;
62- function proxyComponent (
63- componentName : ComponentName
64- ) : FirebaseNamespaceComponent {
45+ function proxyComponent ( componentName : 'auth' ) : typeof firebase . auth ;
46+ function proxyComponent ( componentName : 'analytics' ) : typeof firebase . analytics ;
47+ function proxyComponent ( componentName : 'database' ) : typeof firebase . database ;
48+ function proxyComponent ( componentName : 'firestore' ) : typeof firebase . firestore ;
49+ function proxyComponent ( componentName : 'functions' ) : typeof firebase . functions ;
50+ function proxyComponent ( componentName : 'messaging' ) : typeof firebase . messaging ;
51+ function proxyComponent ( componentName : 'performance' ) : typeof firebase . performance ;
52+ function proxyComponent ( componentName : 'remoteConfig' ) : typeof firebase . remoteConfig ;
53+ function proxyComponent ( componentName : 'storage' ) : typeof firebase . storage ;
54+ function proxyComponent ( componentName : ComponentName ) : FirebaseNamespaceComponent {
6555 let contextualApp : App | undefined ;
6656 const useComponent = ( app ?: App ) => {
6757 contextualApp = useFirebaseApp ( ) ;
@@ -105,65 +95,23 @@ export const performance = usePerformance;
10595export const remoteConfig = useRemoteConfig ;
10696export const storage = useStorage ;
10797
108- function preloadFactory (
109- componentName : 'auth'
110- ) : (
111- firebaseApp ?: App ,
112- settingsCallback ?: ( instanceFactory : App [ 'auth' ] ) => void | Promise < any >
113- ) => Promise < App [ 'auth' ] > ;
114- function preloadFactory (
115- componentName : 'analytics'
116- ) : (
117- firebaseApp ?: App ,
118- settingsCallback ?: ( instanceFactory : App [ 'analytics' ] ) => void | Promise < any >
119- ) => Promise < App [ 'analytics' ] > ;
120- function preloadFactory (
121- componentName : 'database'
122- ) : (
123- firebaseApp ?: App ,
124- settingsCallback ?: ( instanceFactory : App [ 'database' ] ) => void | Promise < any >
125- ) => Promise < App [ 'database' ] > ;
126- function preloadFactory (
127- componentName : 'firestore'
128- ) : (
129- firebaseApp ?: App ,
130- settingsCallback ?: ( instanceFactory : App [ 'firestore' ] ) => void | Promise < any >
131- ) => Promise < App [ 'firestore' ] > ;
132- function preloadFactory (
133- componentName : 'functions'
134- ) : (
135- firebaseApp ?: App ,
136- settingsCallback ?: ( instanceFactory : App [ 'functions' ] ) => void | Promise < any >
137- ) => Promise < App [ 'functions' ] > ;
138- function preloadFactory (
139- componentName : 'messaging'
140- ) : (
141- firebaseApp ?: App ,
142- settingsCallback ?: ( instanceFactory : App [ 'messaging' ] ) => void | Promise < any >
143- ) => Promise < App [ 'messaging' ] > ;
144- function preloadFactory (
145- componentName : 'performance'
146- ) : (
147- firebaseApp ?: App ,
148- settingsCallback ?: ( instanceFactory : App [ 'performance' ] ) => void | Promise < any >
149- ) => Promise < App [ 'performance' ] > ;
150- function preloadFactory (
151- componentName : 'remoteConfig'
152- ) : (
153- firebaseApp ?: App ,
154- settingsCallback ?: ( instanceFactory : App [ 'remoteConfig' ] ) => void | Promise < any >
155- ) => Promise < App [ 'remoteConfig' ] > ;
156- function preloadFactory (
157- componentName : 'storage'
158- ) : (
159- firebaseApp ?: App ,
160- settingsCallback ?: ( instanceFactory : App [ 'storage' ] ) => void | Promise < any >
161- ) => Promise < App [ 'storage' ] > ;
98+ export type PreloadOptions < T > = {
99+ firebaseApp ?: App ;
100+ setup ?: ( instanceFactory : T ) => void | Promise < any >
101+ } ;
102+
103+ function preloadFactory ( componentName : 'auth' ) : ( options ?: PreloadOptions < App [ 'auth' ] > ) => Promise < App [ 'auth' ] > ;
104+ function preloadFactory ( componentName : 'analytics' ) : ( options ?: PreloadOptions < App [ 'analytics' ] > ) => Promise < App [ 'analytics' ] > ;
105+ function preloadFactory ( componentName : 'database' ) : ( options ?: PreloadOptions < App [ 'database' ] > ) => Promise < App [ 'database' ] > ;
106+ function preloadFactory ( componentName : 'firestore' , ) : ( options ?: PreloadOptions < App [ 'firestore' ] > ) => Promise < App [ 'firestore' ] > ;
107+ function preloadFactory ( componentName : 'functions' ) : ( options ?: PreloadOptions < App [ 'functions' ] > ) => Promise < App [ 'functions' ] > ;
108+ function preloadFactory ( componentName : 'messaging' ) : ( options ?: PreloadOptions < App [ 'messaging' ] > ) => Promise < App [ 'messaging' ] > ;
109+ function preloadFactory ( componentName : 'performance' ) : ( options ?: PreloadOptions < App [ 'performance' ] > ) => Promise < App [ 'performance' ] > ;
110+ function preloadFactory ( componentName : 'remoteConfig' ) : ( options ?: PreloadOptions < App [ 'remoteConfig' ] > ) => Promise < App [ 'remoteConfig' ] > ;
111+ function preloadFactory ( componentName : 'storage' ) : ( options ?: PreloadOptions < App [ 'storage' ] > ) => Promise < App [ 'storage' ] > ;
162112function preloadFactory ( componentName : ComponentName ) {
163- return (
164- firebaseApp ?: App ,
165- settingsCallback ?: ( instanceFactory : FirebaseInstanceFactory ) => any
166- ) => preload ( componentName , firebaseApp , settingsCallback ) . toPromise ( ) ;
113+ return ( options ?: PreloadOptions < FirebaseInstanceFactory > ) =>
114+ preload ( componentName , options ?. firebaseApp , options ?. setup ) . toPromise ( ) ;
167115}
168116
169117function preload (
@@ -176,9 +124,7 @@ function preload(
176124 new Observable ( emitter => {
177125 importSDK ( componentName )
178126 . then ( ( ) => {
179- const instanceFactory = app [ componentName ] . bind (
180- app
181- ) as FirebaseInstanceFactory ;
127+ const instanceFactory : FirebaseInstanceFactory = app [ componentName ] . bind ( app ) ;
182128 Promise . resolve ( settingsCallback ( instanceFactory ) ) . then ( ( ) => {
183129 emitter . next ( instanceFactory ) ;
184130 emitter . complete ( ) ;
0 commit comments