UNPKG

9.1 kBJavaScriptView Raw
1import * as i0 from '@angular/core';
2import { InjectionToken, PLATFORM_ID, Injectable, Optional, Inject, NgModule } from '@angular/core';
3import { of, EMPTY, Observable } from 'rxjs';
4import { switchMap, map, shareReplay, tap, first } from 'rxjs/operators';
5import * as i1 from '@angular/fire/compat';
6import { ɵcacheInstance, ɵlazySDKProxy, ɵapplyMixins } from '@angular/fire/compat';
7import { isPlatformBrowser } from '@angular/common';
8import firebase from 'firebase/compat/app';
9import { VERSION } from '@angular/fire';
10
11// DO NOT MODIFY, this file is autogenerated by tools/build.ts
12// Export a null object with the same keys as firebase/compat/performance, so Proxy can work with proxy-polyfill in Internet Explorer
13const proxyPolyfillCompat = {
14 app: null,
15 trace: null,
16 instrumentationEnabled: null,
17 dataCollectionEnabled: null,
18};
19
20const INSTRUMENTATION_ENABLED = new InjectionToken('angularfire2.performance.instrumentationEnabled');
21const DATA_COLLECTION_ENABLED = new InjectionToken('angularfire2.performance.dataCollectionEnabled');
22class AngularFirePerformance {
23 constructor(app, instrumentationEnabled, dataCollectionEnabled, zone,
24 // tslint:disable-next-line:ban-types
25 platformId) {
26 this.zone = zone;
27 this.performance = of(undefined).pipe(switchMap(() => isPlatformBrowser(platformId) ? zone.runOutsideAngular(() => import('firebase/compat/performance')) : EMPTY), map(() => ɵcacheInstance(`performance`, 'AngularFirePerformance', app.name, () => {
28 const performance = zone.runOutsideAngular(() => app.performance());
29 if (instrumentationEnabled === false) {
30 performance.instrumentationEnabled = false;
31 }
32 if (dataCollectionEnabled === false) {
33 performance.dataCollectionEnabled = false;
34 }
35 return performance;
36 }, [instrumentationEnabled, dataCollectionEnabled])), shareReplay({ bufferSize: 1, refCount: false }));
37 return ɵlazySDKProxy(this, this.performance, zone);
38 }
39}
40AngularFirePerformance.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: AngularFirePerformance, deps: [{ token: i1.FirebaseApp }, { token: INSTRUMENTATION_ENABLED, optional: true }, { token: DATA_COLLECTION_ENABLED, optional: true }, { token: i0.NgZone }, { token: PLATFORM_ID }], target: i0.ɵɵFactoryTarget.Injectable });
41AngularFirePerformance.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: AngularFirePerformance, providedIn: 'any' });
42i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: AngularFirePerformance, decorators: [{
43 type: Injectable,
44 args: [{
45 providedIn: 'any'
46 }]
47 }], ctorParameters: function () { return [{ type: i1.FirebaseApp }, { type: undefined, decorators: [{
48 type: Optional
49 }, {
50 type: Inject,
51 args: [INSTRUMENTATION_ENABLED]
52 }] }, { type: undefined, decorators: [{
53 type: Optional
54 }, {
55 type: Inject,
56 args: [DATA_COLLECTION_ENABLED]
57 }] }, { type: i0.NgZone }, { type: Object, decorators: [{
58 type: Inject,
59 args: [PLATFORM_ID]
60 }] }]; } });
61const trace$ = (traceId) => {
62 var _a;
63 if (typeof window !== 'undefined' && ((_a = window.performance) === null || _a === void 0 ? void 0 : _a.mark)) {
64 const entries = window.performance.getEntriesByName(traceId, 'measure') || [];
65 const startMarkName = `_${traceId}Start[${entries.length}]`;
66 const endMarkName = `_${traceId}End[${entries.length}]`;
67 return new Observable(emitter => {
68 window.performance.mark(startMarkName);
69 emitter.next();
70 return {
71 unsubscribe: () => {
72 window.performance.mark(endMarkName);
73 window.performance.measure(traceId, startMarkName, endMarkName);
74 }
75 };
76 });
77 }
78 else {
79 return EMPTY;
80 }
81};
82const traceUntil = (name, test, options) => (source$) => new Observable(subscriber => {
83 const traceSubscription = trace$(name).subscribe();
84 return source$.pipe(tap(a => test(a) && traceSubscription.unsubscribe(), () => {
85 }, () => options && options.orComplete && traceSubscription.unsubscribe())).subscribe(subscriber);
86});
87const traceWhile = (name, test, options) => (source$) => new Observable(subscriber => {
88 let traceSubscription;
89 return source$.pipe(tap(a => {
90 if (test(a)) {
91 traceSubscription = traceSubscription || trace$(name).subscribe();
92 }
93 else {
94 if (traceSubscription) {
95 traceSubscription.unsubscribe();
96 }
97 traceSubscription = undefined;
98 }
99 }, () => {
100 }, () => options && options.orComplete && traceSubscription && traceSubscription.unsubscribe())).subscribe(subscriber);
101});
102const traceUntilComplete = (name) => (source$) => new Observable(subscriber => {
103 const traceSubscription = trace$(name).subscribe();
104 return source$.pipe(tap(() => {
105 }, () => {
106 }, () => traceSubscription.unsubscribe())).subscribe(subscriber);
107});
108const traceUntilFirst = (name) => (source$) => new Observable(subscriber => {
109 const traceSubscription = trace$(name).subscribe();
110 return source$.pipe(tap(() => traceSubscription.unsubscribe(), () => {
111 }, () => {
112 })).subscribe(subscriber);
113});
114const trace = (name) => (source$) => new Observable(subscriber => {
115 const traceSubscription = trace$(name).subscribe();
116 return source$.pipe(tap(() => traceSubscription.unsubscribe(), () => {
117 }, () => traceSubscription.unsubscribe())).subscribe(subscriber);
118});
119ɵapplyMixins(AngularFirePerformance, [proxyPolyfillCompat]);
120
121const IS_STABLE_START_MARK = 'Zone';
122const IS_STABLE_END_MARK = '_isStableEnd';
123class PerformanceMonitoringService {
124 constructor(appRef) {
125 var _a;
126 if (typeof window !== 'undefined' && ((_a = window.performance) === null || _a === void 0 ? void 0 : _a.mark)) {
127 this.disposable = appRef.isStable.pipe(first(it => it), tap(() => {
128 window.performance.mark(IS_STABLE_END_MARK);
129 window.performance.measure('isStable', IS_STABLE_START_MARK, IS_STABLE_END_MARK);
130 })).subscribe();
131 }
132 }
133 ngOnDestroy() {
134 if (this.disposable) {
135 this.disposable.unsubscribe();
136 }
137 }
138}
139PerformanceMonitoringService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: PerformanceMonitoringService, deps: [{ token: i0.ApplicationRef }], target: i0.ɵɵFactoryTarget.Injectable });
140PerformanceMonitoringService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: PerformanceMonitoringService });
141i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: PerformanceMonitoringService, decorators: [{
142 type: Injectable
143 }], ctorParameters: function () { return [{ type: i0.ApplicationRef }]; } });
144
145class AngularFirePerformanceModule {
146 constructor(perf, _) {
147 firebase.registerVersion('angularfire', VERSION.full, 'perf-compat');
148 // call anything here to get perf loading
149 // tslint:disable-next-line:no-unused-expression
150 perf.dataCollectionEnabled.then(() => { });
151 }
152}
153AngularFirePerformanceModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: AngularFirePerformanceModule, deps: [{ token: AngularFirePerformance }, { token: PerformanceMonitoringService, optional: true }], target: i0.ɵɵFactoryTarget.NgModule });
154AngularFirePerformanceModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: AngularFirePerformanceModule });
155AngularFirePerformanceModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: AngularFirePerformanceModule, providers: [AngularFirePerformance] });
156i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.3", ngImport: i0, type: AngularFirePerformanceModule, decorators: [{
157 type: NgModule,
158 args: [{
159 providers: [AngularFirePerformance]
160 }]
161 }], ctorParameters: function () { return [{ type: AngularFirePerformance }, { type: PerformanceMonitoringService, decorators: [{
162 type: Optional
163 }] }]; } });
164
165/**
166 * Generated bundle index. Do not edit.
167 */
168
169export { AngularFirePerformance, AngularFirePerformanceModule, DATA_COLLECTION_ENABLED, INSTRUMENTATION_ENABLED, PerformanceMonitoringService, trace, traceUntil, traceUntilComplete, traceUntilFirst, traceWhile };
170//# sourceMappingURL=angular-fire-compat-performance.js.map