Skip to content

Commit 79e93f1

Browse files
committed
migrate installations to component
1 parent 8de5d2f commit 79e93f1

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

packages/installations/src/index.ts

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,34 @@
1717

1818
import firebase from '@firebase/app';
1919
import {
20-
_FirebaseNamespace,
21-
FirebaseServiceFactory
20+
_FirebaseNamespace
2221
} from '@firebase/app-types/private';
2322
import { FirebaseInstallations } from '@firebase/installations-types';
2423

2524
import { deleteInstallation, getId, getToken } from './functions';
2625
import { extractAppConfig } from './helpers/extract-app-config';
26+
import { Provider, Component, ComponentType } from '@firebase/component';
27+
import { FirebaseApp } from '@firebase/app-types';
2728

2829
export function registerInstallations(instance: _FirebaseNamespace): void {
2930
const installationsName = 'installations';
3031

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);
3438

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+
));
4448
}
4549

4650
registerInstallations(firebase as _FirebaseNamespace);
@@ -56,3 +60,9 @@ declare module '@firebase/app-types' {
5660
installations(): FirebaseInstallations;
5761
}
5862
}
63+
64+
declare module '@firebase/component' {
65+
interface ComponentContainer {
66+
getProvider(name: 'installations'): Provider<FirebaseInstallations>;
67+
}
68+
}

0 commit comments

Comments
 (0)