Skip to content

Commit 3fc0801

Browse files
committed
Migrate installations to component framework (#2322)
* Migrate installations to component framework * remove unused import * update calling code according to the latest component changes * added forceRefresh back
1 parent 7e1515b commit 3fc0801

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

packages/installations/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"dependencies": {
5454
"@firebase/installations-types": "0.2.1",
5555
"@firebase/util": "0.2.31",
56+
"@firebase/component": "0.1.0",
5657
"idb": "3.0.2",
5758
"tslib": "1.10.0"
5859
}

packages/installations/src/index.ts

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,34 @@
1616
*/
1717

1818
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';
2320
import { FirebaseInstallations } from '@firebase/installations-types';
2421

2522
import { deleteInstallation, getId, getToken } from './functions';
2623
import { extractAppConfig } from './helpers/extract-app-config';
24+
import { Provider, Component, ComponentType } from '@firebase/component';
2725

2826
export function registerInstallations(instance: _FirebaseNamespace): void {
2927
const installationsName = 'installations';
3028

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

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+
);
4447
}
4548

4649
registerInstallations(firebase as _FirebaseNamespace);
@@ -56,3 +59,9 @@ declare module '@firebase/app-types' {
5659
installations(): FirebaseInstallations;
5760
}
5861
}
62+
63+
declare module '@firebase/component' {
64+
interface ComponentContainer {
65+
getProvider(name: 'installations'): Provider<FirebaseInstallations>;
66+
}
67+
}

0 commit comments

Comments
 (0)