Skip to content

Commit daa4c25

Browse files
authored
feat(performance): Add Performance
1 parent 8fce342 commit daa4c25

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/performance/performance.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Inject, Injectable, InjectionToken, NgZone, Optional, PLATFORM_ID } from '@angular/core';
22
import { EMPTY, Observable, of, Subscription } from 'rxjs';
33
import { map, shareReplay, switchMap, tap } from 'rxjs/operators';
4-
import firebase from 'firebase/app';
4+
import { FirebasePerformance, initializePerformance } from 'firebase/performance';
55
import { FirebaseApp, ɵapplyMixins, ɵlazySDKProxy, ɵPromiseProxy } from '@angular/fire';
66
import { isPlatformBrowser } from '@angular/common';
77
import { proxyPolyfillCompat } from './base';
@@ -12,15 +12,15 @@ export const AUTOMATICALLY_TRACE_CORE_NG_METRICS = new InjectionToken<boolean>('
1212
export const INSTRUMENTATION_ENABLED = new InjectionToken<boolean>('angularfire2.performance.instrumentationEnabled');
1313
export const DATA_COLLECTION_ENABLED = new InjectionToken<boolean>('angularfire2.performance.dataCollectionEnabled');
1414

15-
export interface AngularFirePerformance extends ɵPromiseProxy<firebase.performance.Performance> {
15+
export interface AngularFirePerformance extends ɵPromiseProxy<FirebasePerformance> {
1616
}
1717

1818
@Injectable({
1919
providedIn: 'any'
2020
})
2121
export class AngularFirePerformance {
2222

23-
private readonly performance: Observable<firebase.performance.Performance>;
23+
private readonly performance: Observable<FirebasePerformance>;
2424

2525
constructor(
2626
app: FirebaseApp,
@@ -34,13 +34,12 @@ export class AngularFirePerformance {
3434
this.performance = of(undefined).pipe(
3535
switchMap(() => isPlatformBrowser(platformId) ? zone.runOutsideAngular(() => import('firebase/performance')) : EMPTY),
3636
map(() => ɵfetchInstance(`performance`, 'AngularFirePerformance', app, () => {
37-
const performance = zone.runOutsideAngular(() => app.performance());
38-
if (instrumentationEnabled === false) {
39-
performance.instrumentationEnabled = false;
40-
}
41-
if (dataCollectionEnabled === false) {
42-
performance.dataCollectionEnabled = false;
43-
}
37+
const performance = zone.runOutsideAngular(() => {
38+
return initializePerformance(app, {
39+
instrumentationEnabled,
40+
dataCollectionEnabled
41+
});
42+
});
4443
return performance;
4544
}, [instrumentationEnabled, dataCollectionEnabled])),
4645
shareReplay({ bufferSize: 1, refCount: false })

0 commit comments

Comments
 (0)