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' ;
27
25
28
26
export function registerInstallations ( instance : _FirebaseNamespace ) : void {
29
27
const installationsName = 'installations' ;
30
28
31
- const factoryMethod : FirebaseServiceFactory = app => {
32
- // Throws if app isn't configured properly.
33
- extractAppConfig ( app ) ;
29
+ instance . INTERNAL . registerComponent (
30
+ new Component (
31
+ installationsName ,
32
+ container => {
33
+ const app = container . getProvider ( 'app' ) . getImmediate ( ) ;
34
+ // Throws if app isn't configured properly.
35
+ extractAppConfig ( app ) ;
34
36
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 ) ;
37
+ return {
38
+ app,
39
+ getId : ( ) => getId ( app ) ,
40
+ getToken : ( forceRefresh ?: boolean ) => getToken ( app , forceRefresh ) ,
41
+ delete : ( ) => deleteInstallation ( app )
42
+ } ;
43
+ } ,
44
+ ComponentType . PUBLIC
45
+ )
46
+ ) ;
44
47
}
45
48
46
49
registerInstallations ( firebase as _FirebaseNamespace ) ;
@@ -56,3 +59,9 @@ declare module '@firebase/app-types' {
56
59
installations ( ) : FirebaseInstallations ;
57
60
}
58
61
}
62
+
63
+ declare module '@firebase/component' {
64
+ interface ComponentContainer {
65
+ getProvider ( name : 'installations' ) : Provider < FirebaseInstallations > ;
66
+ }
67
+ }
0 commit comments