16
16
*/
17
17
18
18
import firebase from '@firebase/app' ;
19
- import {
20
- _FirebaseNamespace ,
21
- FirebaseServiceFactory
22
- } from '@firebase/app-types/private' ;
19
+ import { _FirebaseNamespace } from '@firebase/app-types/private' ;
23
20
import { FirebaseInstallations } from '@firebase/installations-types' ;
24
21
25
22
import { deleteInstallation , getId , getToken } from './functions' ;
26
23
import { extractAppConfig } from './helpers/extract-app-config' ;
24
+ import { Provider , Component , ComponentType } from '@firebase/component' ;
25
+ import { FirebaseApp } from '@firebase/app-types' ;
27
26
28
27
export function registerInstallations ( instance : _FirebaseNamespace ) : void {
29
28
const installationsName = 'installations' ;
30
29
31
- const factoryMethod : FirebaseServiceFactory = app => {
32
- // Throws if app isn't configured properly.
33
- extractAppConfig ( app ) ;
30
+ instance . INTERNAL . registerComponent (
31
+ new Component (
32
+ installationsName ,
33
+ container => {
34
+ const app = container . getProvider < FirebaseApp > ( 'app' ) . getImmediate ( ) ! ;
35
+ // Throws if app isn't configured properly.
36
+ extractAppConfig ( app ) ;
34
37
35
- return {
36
- app,
37
- getId : ( ) => getId ( app ) ,
38
- getToken : ( forceRefresh ?: boolean ) => getToken ( app , forceRefresh ) ,
39
- delete : ( ) => deleteInstallation ( app )
40
- } ;
41
- } ;
42
-
43
- instance . INTERNAL . registerService ( installationsName , factoryMethod ) ;
38
+ return {
39
+ app,
40
+ getId : ( ) => getId ( app ) ,
41
+ getToken : ( ) => getToken ( app ) ,
42
+ delete : ( ) => deleteInstallation ( app )
43
+ } ;
44
+ } ,
45
+ ComponentType . PUBLIC
46
+ )
47
+ ) ;
44
48
}
45
49
46
50
registerInstallations ( firebase as _FirebaseNamespace ) ;
@@ -56,3 +60,9 @@ declare module '@firebase/app-types' {
56
60
installations ( ) : FirebaseInstallations ;
57
61
}
58
62
}
63
+
64
+ declare module '@firebase/component' {
65
+ interface ComponentContainer {
66
+ getProvider ( name : 'installations' ) : Provider < FirebaseInstallations > ;
67
+ }
68
+ }
0 commit comments