1
1
import { Inject , Injectable , InjectionToken , NgZone , Optional , PLATFORM_ID } from '@angular/core' ;
2
2
import { EMPTY , Observable , of , Subscription } from 'rxjs' ;
3
3
import { map , shareReplay , switchMap , tap } from 'rxjs/operators' ;
4
- import firebase from 'firebase/app ' ;
4
+ import { FirebasePerformance , initializePerformance } from 'firebase/performance ' ;
5
5
import { FirebaseApp , ɵapplyMixins , ɵlazySDKProxy , ɵPromiseProxy } from '@angular/fire' ;
6
6
import { isPlatformBrowser } from '@angular/common' ;
7
7
import { proxyPolyfillCompat } from './base' ;
@@ -12,15 +12,15 @@ export const AUTOMATICALLY_TRACE_CORE_NG_METRICS = new InjectionToken<boolean>('
12
12
export const INSTRUMENTATION_ENABLED = new InjectionToken < boolean > ( 'angularfire2.performance.instrumentationEnabled' ) ;
13
13
export const DATA_COLLECTION_ENABLED = new InjectionToken < boolean > ( 'angularfire2.performance.dataCollectionEnabled' ) ;
14
14
15
- export interface AngularFirePerformance extends ɵPromiseProxy < firebase . performance . Performance > {
15
+ export interface AngularFirePerformance extends ɵPromiseProxy < FirebasePerformance > {
16
16
}
17
17
18
18
@Injectable ( {
19
19
providedIn : 'any'
20
20
} )
21
21
export class AngularFirePerformance {
22
22
23
- private readonly performance : Observable < firebase . performance . Performance > ;
23
+ private readonly performance : Observable < FirebasePerformance > ;
24
24
25
25
constructor (
26
26
app : FirebaseApp ,
@@ -34,13 +34,12 @@ export class AngularFirePerformance {
34
34
this . performance = of ( undefined ) . pipe (
35
35
switchMap ( ( ) => isPlatformBrowser ( platformId ) ? zone . runOutsideAngular ( ( ) => import ( 'firebase/performance' ) ) : EMPTY ) ,
36
36
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
+ } ) ;
44
43
return performance ;
45
44
} , [ instrumentationEnabled , dataCollectionEnabled ] ) ) ,
46
45
shareReplay ( { bufferSize : 1 , refCount : false } )
0 commit comments