17
17
18
18
import firebase from '@firebase/app' ;
19
19
import {
20
- _FirebaseNamespace ,
21
- FirebaseServiceFactory
20
+ _FirebaseNamespace
22
21
} from '@firebase/app-types/private' ;
23
22
import { FirebaseInstallations } from '@firebase/installations-types' ;
24
23
25
24
import { deleteInstallation , getId , getToken } from './functions' ;
26
25
import { extractAppConfig } from './helpers/extract-app-config' ;
26
+ import { Provider , Component , ComponentType } from '@firebase/component' ;
27
+ import { FirebaseApp } from '@firebase/app-types' ;
27
28
28
29
export function registerInstallations ( instance : _FirebaseNamespace ) : void {
29
30
const installationsName = 'installations' ;
30
31
31
- const factoryMethod : FirebaseServiceFactory = app => {
32
- // Throws if app isn't configured properly.
33
- extractAppConfig ( app ) ;
32
+ instance . INTERNAL . registerComponent ( new Component (
33
+ installationsName ,
34
+ container => {
35
+ const app = container . getProvider < FirebaseApp > ( 'app' ) . getImmediate ( ) ! ;
36
+ // Throws if app isn't configured properly.
37
+ extractAppConfig ( app ) ;
34
38
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 ) ;
39
+ return {
40
+ app,
41
+ getId : ( ) => getId ( app ) ,
42
+ getToken : ( ) => getToken ( app ) ,
43
+ delete : ( ) => deleteInstallation ( app )
44
+ } ;
45
+ } ,
46
+ ComponentType . PUBLIC
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