Skip to content

Commit 5a6c4d6

Browse files
committed
Adding AUTOMATICALLY_TRACE_CORE_NG_METRICS InjectionToken and getting tests working
1 parent db73285 commit 5a6c4d6

File tree

10 files changed

+26
-28
lines changed

10 files changed

+26
-28
lines changed

karma.conf.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ module.exports = function(config) {
3030
'node_modules/firebase/firebase-database.js',
3131
'node_modules/firebase/firebase-firestore.js',
3232
'node_modules/firebase/firebase-functions.js',
33+
'node_modules/firebase/firebase-performance.js',
3334
'node_modules/firebase/firebase-storage.js',
3435
'dist/packages-dist/bundles/core.umd.{js,map}',
3536
'dist/packages-dist/bundles/auth.umd.{js,map}',
3637
'dist/packages-dist/bundles/database.umd.{js,map}',
3738
'dist/packages-dist/bundles/firestore.umd.{js,map}',
3839
'dist/packages-dist/bundles/functions.umd.{js,map}',
3940
'dist/packages-dist/bundles/storage.umd.{js,map}',
41+
'dist/packages-dist/bundles/performance.umd.{js,map}',
4042
'dist/packages-dist/bundles/database-deprecated.umd.{js,map}',
4143
'dist/packages-dist/bundles/test.umd.{js,map}',
4244
],

src/core/firebase.app.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class FirebaseApp {
2525
auth: () => FirebaseAuth;
2626
database: (databaseURL?: string) => FirebaseDatabase;
2727
messaging: () => FirebaseMessaging;
28-
performance: () => any;
28+
performance: () => any; // SEMVER: once >= 6 import performance.Performance
2929
storage: (storageBucket?: string) => FirebaseStorage;
3030
delete: () => Promise<void>;
3131
firestore: () => FirebaseFirestore;

src/performance/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
"@angular/core": "ANGULAR_VERSION",
2323
"@angular/platform-browser": "ANGULAR_VERSION",
2424
"@angular/platform-browser-dynamic": "ANGULAR_VERSION",
25-
"@firebase/app": "FIREBASE_APP_VERSION",
26-
"@firebase/messaging": "FIREBASE_MESSAGING_VERSION",
25+
"firebase": "FIREBASE_VERSION",
2726
"rxjs": "RXJS_VERSION",
2827
"zone.js": "ZONEJS_VERSION"
2928
},

src/performance/performance.module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { NgModule } from '@angular/core';
22
import { AngularFirePerformance } from './performance';
3+
34
import 'firebase/performance';
45

56
@NgModule({

src/performance/performance.spec.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,4 @@ describe('AngularFirePerformance', () => {
3333
expect(afp.performance).toBeDefined();
3434
});
3535

36-
it('should have an initialized Firebase app', () => {
37-
expect(afp.performance.app).toBeDefined();
38-
expect(afp.performance.app).toEqual(app);
39-
});
40-
4136
});

src/performance/performance.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { Injectable, Inject, Optional, NgZone, ApplicationRef } from '@angular/core';
1+
import { Injectable, NgZone, ApplicationRef, InjectionToken, Inject, Optional } from '@angular/core';
22
import { Observable } from 'rxjs';
3-
import { filter, tap, take } from 'rxjs/operators';
4-
import { FirebaseOptions, FirebaseAppConfig } from '@angular/fire';
5-
import { FirebaseOptionsToken, FirebaseNameOrConfigToken, _firebaseAppFactory } from '@angular/fire';
3+
import { first, tap } from 'rxjs/operators';
64
import { performance } from 'firebase/app';
75

6+
export const AUTOMATICALLY_TRACE_CORE_NG_METRICS = new InjectionToken<boolean>('angularfire2.performance.auto_trace');
7+
88
export type TraceOptions = {
99
metrics: {[key:string]: number},
1010
attributes?:{[key:string]:string},
@@ -19,23 +19,22 @@ export class AngularFirePerformance {
1919
performance: performance.Performance;
2020

2121
constructor(
22-
@Inject(FirebaseOptionsToken) options:FirebaseOptions,
23-
@Optional() @Inject(FirebaseNameOrConfigToken) nameOrConfig:string|FirebaseAppConfig|null|undefined,
22+
@Optional() @Inject(AUTOMATICALLY_TRACE_CORE_NG_METRICS) automaticallyTraceCoreNgMetrics:boolean|null,
2423
appRef: ApplicationRef,
2524
private zone: NgZone
2625
) {
2726

28-
this.performance = zone.runOutsideAngular(() => {
29-
const app = _firebaseAppFactory(options, nameOrConfig);
30-
return app.performance();
31-
});
27+
this.performance = zone.runOutsideAngular(() => performance());
3228

33-
// TODO detirmine more built in metrics
34-
appRef.isStable.pipe(
35-
this.traceComplete('isStable'),
36-
filter(it => it),
37-
take(1)
38-
).subscribe();
29+
if (automaticallyTraceCoreNgMetrics != false) {
30+
31+
// TODO detirmine more built in metrics
32+
appRef.isStable.pipe(
33+
this.traceComplete('isStable'),
34+
first(it => it)
35+
).subscribe();
36+
37+
}
3938

4039
}
4140

src/performance/test-config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ export const COMMON_CONFIG = {
33
apiKey: "AIzaSyBVSy3YpkVGiKXbbxeK0qBnu3-MNZ9UIjA",
44
authDomain: "angularfire2-test.firebaseapp.com",
55
databaseURL: "https://angularfire2-test.firebaseio.com",
6+
projectId: "angularfire2-test",
67
storageBucket: "angularfire2-test.appspot.com",
7-
messagingSenderId: "920323787688"
8+
messagingSenderId: "920323787688",
9+
appId: "1:920323787688:web:2253a0e5eb5b9a8b"
810
};

src/performance/tsconfig-test.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
"compilerOptions": {
44
"baseUrl": ".",
55
"paths": {
6-
"@angular/fire": ["../../dist/packages-dist"],
7-
"@angular/fire/performance": ["../../dist/packages-dist/performance"]
6+
"@angular/fire": ["../../dist/packages-dist"]
87
}
98
},
109
"files": [

src/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"@angular/fire/functions": ["./functions"],
1818
"@angular/fire/storage": ["./storage"],
1919
"@angular/fire/messaging": ["./messaging"],
20+
"@angular/fire/performance": ["./performance"],
2021
"@angular/fire/database-deprecated": ["./database-deprecated"]
2122
},
2223
"rootDir": ".",

tools/build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const GLOBALS = {
2323
'firebase/messaging': 'firebase',
2424
'firebase/firestore': 'firebase',
2525
'firebase/functions': 'firebase',
26-
'firebase/perf': 'firebase',
26+
'firebase/performance': 'firebase',
2727
'firebase/storage': 'firebase',
2828
'@angular/fire': 'angularfire2',
2929
'@angular/fire/auth': 'angularfire2.auth',

0 commit comments

Comments
 (0)