Skip to content

Commit 520dc58

Browse files
committed
Migrate installations to component framework
1 parent af4fdc4 commit 520dc58

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

packages/app-types/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Provider } from '@firebase/component';
2+
13
/**
24
* @license
35
* Copyright 2017 Google Inc.

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: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,35 @@
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';
25+
import { FirebaseApp } from '@firebase/app-types';
2726

2827
export function registerInstallations(instance: _FirebaseNamespace): void {
2928
const installationsName = 'installations';
3029

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

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