Skip to content

Commit ae0ef48

Browse files
chore(lint): Clean perf files
1 parent 1318921 commit ae0ef48

File tree

3 files changed

+59
-33
lines changed

3 files changed

+59
-33
lines changed

src/performance/performance.module.ts

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export class AngularFirePerformanceModule {
1111
@Optional() _: PerformanceMonitoringService
1212
) {
1313
// call anything here to get perf loading
14+
// tslint:disable-next-line:no-unused-expression
1415
perf.dataCollectionEnabled;
1516
}
1617
}

src/performance/performance.spec.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { inject, TestBed } from '@angular/core/testing';
1+
import { TestBed } from '@angular/core/testing';
22
import { AngularFireModule, FirebaseApp } from '@angular/fire';
33
import { AngularFirePerformance, AngularFirePerformanceModule } from './public_api';
44
import { COMMON_CONFIG } from '../test-config';
@@ -15,10 +15,9 @@ describe('AngularFirePerformance', () => {
1515
AngularFirePerformanceModule
1616
]
1717
});
18-
inject([FirebaseApp, AngularFirePerformance], (app_: FirebaseApp, _perf: AngularFirePerformance) => {
19-
app = app_;
20-
afp = _perf;
21-
})();
18+
19+
app = TestBed.inject(FirebaseApp);
20+
afp = TestBed.inject(AngularFirePerformance);
2221
});
2322

2423
afterEach(() => {

src/performance/performance.ts

+54-28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Inject, Injectable, InjectionToken, NgZone, Optional, PLATFORM_ID } from '@angular/core';
2-
import { empty, Observable, of, Subscription } from 'rxjs';
2+
import { EMPTY, empty, Observable, of, Subscription } from 'rxjs';
33
import { map, shareReplay, switchMap, tap } from 'rxjs/operators';
44
import { performance } from 'firebase/app';
55
import { FirebaseApp, ɵlazySDKProxy, ɵPromiseProxy } from '@angular/fire';
@@ -10,7 +10,8 @@ export const AUTOMATICALLY_TRACE_CORE_NG_METRICS = new InjectionToken<boolean>('
1010
export const INSTRUMENTATION_ENABLED = new InjectionToken<boolean>('angularfire2.performance.instrumentationEnabled');
1111
export const DATA_COLLECTION_ENABLED = new InjectionToken<boolean>('angularfire2.performance.dataCollectionEnabled');
1212

13-
export interface AngularFirePerformance extends ɵPromiseProxy<performance.Performance> {}
13+
export interface AngularFirePerformance extends ɵPromiseProxy<performance.Performance> {
14+
}
1415

1516
@Injectable({
1617
providedIn: 'any'
@@ -21,20 +22,25 @@ export class AngularFirePerformance {
2122

2223
constructor(
2324
app: FirebaseApp,
24-
@Optional() @Inject(INSTRUMENTATION_ENABLED) instrumentationEnabled: boolean|null,
25-
@Optional() @Inject(DATA_COLLECTION_ENABLED) dataCollectionEnabled: boolean|null,
25+
@Optional() @Inject(INSTRUMENTATION_ENABLED) instrumentationEnabled: boolean | null,
26+
@Optional() @Inject(DATA_COLLECTION_ENABLED) dataCollectionEnabled: boolean | null,
2627
private zone: NgZone,
28+
// tslint:disable-next-line:ban-types
2729
@Inject(PLATFORM_ID) platformId: Object
2830
) {
2931

3032
this.performance = of(undefined).pipe(
31-
switchMap(() => isPlatformBrowser(platformId) ? zone.runOutsideAngular(() => import('firebase/performance')) : empty()),
33+
switchMap(() => isPlatformBrowser(platformId) ? zone.runOutsideAngular(() => import('firebase/performance')) : EMPTY),
3234
map(() => zone.runOutsideAngular(() => app.performance())),
3335
tap(performance => {
34-
if (instrumentationEnabled == false) { performance.instrumentationEnabled = false; }
35-
if (dataCollectionEnabled == false) { performance.dataCollectionEnabled = false; }
36+
if (instrumentationEnabled !== true) {
37+
performance.instrumentationEnabled = false;
38+
}
39+
if (dataCollectionEnabled !== true) {
40+
performance.dataCollectionEnabled = false;
41+
}
3642
}),
37-
shareReplay({ bufferSize: 1, refCount: false }),
43+
shareReplay({ bufferSize: 1, refCount: false })
3844
);
3945

4046
return ɵlazySDKProxy(this, this.performance, zone);
@@ -51,73 +57,93 @@ const trace$ = (traceId: string) => {
5157
return new Observable<void>(emitter => {
5258
window.performance.mark(startMarkName);
5359
emitter.next();
54-
return { unsubscribe: () => {
55-
window.performance.mark(endMarkName);
56-
window.performance.measure(traceId, startMarkName, endMarkName);
57-
}};
60+
return {
61+
unsubscribe: () => {
62+
window.performance.mark(endMarkName);
63+
window.performance.measure(traceId, startMarkName, endMarkName);
64+
}
65+
};
5866
});
5967
} else {
6068
return empty();
6169
}
6270
};
6371

64-
export const traceUntil = <T= any>(name: string, test: (a: T) => boolean, options?: { orComplete?: boolean }) => (source$: Observable<T>) => new Observable<T>(subscriber => {
72+
export const traceUntil = <T = any>(
73+
name: string,
74+
test: (a: T) => boolean,
75+
options?: { orComplete?: boolean }
76+
) => (source$: Observable<T>) => new Observable<T>(subscriber => {
6577
const traceSubscription = trace$(name).subscribe();
6678
return source$.pipe(
6779
tap(
68-
a => test(a) && traceSubscription.unsubscribe(),
69-
() => {},
80+
a => test(a) && traceSubscription.unsubscribe(),
81+
() => {
82+
},
7083
() => options && options.orComplete && traceSubscription.unsubscribe()
7184
)
7285
).subscribe(subscriber);
7386
});
7487

75-
export const traceWhile = <T= any>(name: string, test: (a: T) => boolean, options?: { orComplete?: boolean}) => (source$: Observable<T>) => new Observable<T>(subscriber => {
76-
let traceSubscription: Subscription|undefined;
88+
export const traceWhile = <T = any>(
89+
name: string,
90+
test: (a: T) => boolean,
91+
options?: { orComplete?: boolean }
92+
) => (source$: Observable<T>) => new Observable<T>(subscriber => {
93+
let traceSubscription: Subscription | undefined;
7794
return source$.pipe(
7895
tap(
79-
a => {
96+
a => {
8097
if (test(a)) {
8198
traceSubscription = traceSubscription || trace$(name).subscribe();
8299
} else {
83-
traceSubscription && traceSubscription.unsubscribe();
100+
if (traceSubscription) {
101+
traceSubscription.unsubscribe();
102+
}
103+
84104
traceSubscription = undefined;
85105
}
86106
},
87-
() => {},
107+
() => {
108+
},
88109
() => options && options.orComplete && traceSubscription && traceSubscription.unsubscribe()
89110
)
90111
).subscribe(subscriber);
91112
});
92113

93-
export const traceUntilComplete = <T= any>(name: string) => (source$: Observable<T>) => new Observable<T>(subscriber => {
114+
export const traceUntilComplete = <T = any>(name: string) => (source$: Observable<T>) => new Observable<T>(subscriber => {
94115
const traceSubscription = trace$(name).subscribe();
95116
return source$.pipe(
96117
tap(
97-
() => {},
98-
() => {},
118+
() => {
119+
},
120+
() => {
121+
},
99122
() => traceSubscription.unsubscribe()
100123
)
101124
).subscribe(subscriber);
102125
});
103126

104-
export const traceUntilFirst = <T= any>(name: string) => (source$: Observable<T>) => new Observable<T>(subscriber => {
127+
export const traceUntilFirst = <T = any>(name: string) => (source$: Observable<T>) => new Observable<T>(subscriber => {
105128
const traceSubscription = trace$(name).subscribe();
106129
return source$.pipe(
107130
tap(
108131
() => traceSubscription.unsubscribe(),
109-
() => {},
110-
() => {}
132+
() => {
133+
},
134+
() => {
135+
}
111136
)
112137
).subscribe(subscriber);
113138
});
114139

115-
export const trace = <T= any>(name: string) => (source$: Observable<T>) => new Observable<T>(subscriber => {
140+
export const trace = <T = any>(name: string) => (source$: Observable<T>) => new Observable<T>(subscriber => {
116141
const traceSubscription = trace$(name).subscribe();
117142
return source$.pipe(
118143
tap(
119144
() => traceSubscription.unsubscribe(),
120-
() => {},
145+
() => {
146+
},
121147
() => traceSubscription.unsubscribe()
122148
)
123149
).subscribe(subscriber);

0 commit comments

Comments
 (0)