Skip to content

Commit caac210

Browse files
committed
Reworking performance a bit more
1 parent 1f1c69c commit caac210

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

src/performance/performance.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Injectable, NgZone, ApplicationRef, InjectionToken, Inject, Optional } from '@angular/core';
2-
import { Observable } from 'rxjs';
2+
import { Observable, Subscription } from 'rxjs';
33
import { first, tap } from 'rxjs/operators';
44
import { performance } from 'firebase/app';
55

@@ -37,7 +37,7 @@ export class AngularFirePerformance {
3737

3838
// TODO determine more built in metrics
3939
appRef.isStable.pipe(
40-
this.traceUntilLast('isStable'),
40+
this.traceUntilComplete('isStable'),
4141
first(it => it)
4242
).subscribe();
4343

@@ -73,21 +73,35 @@ export class AngularFirePerformance {
7373
})
7474
);
7575

76-
traceUntil = <T=any>(name:string, test: (a:T) => boolean, options?: TraceOptions) => (source$: Observable<T>) => {
76+
traceUntil = <T=any>(name:string, test: (a:T) => boolean, options?: TraceOptions & { orComplete: boolean }) => (source$: Observable<T>) => {
7777
const traceSubscription = this.trace$(name, options).subscribe();
7878
return source$.pipe(
79-
tap(a => { if (test(a)) { traceSubscription.unsubscribe() }})
79+
tap(
80+
a => test(a) && traceSubscription.unsubscribe(),
81+
() => {},
82+
() => options && options.orComplete && traceSubscription.unsubscribe()
83+
)
8084
)
8185
};
8286

83-
traceWhile = <T=any>(name:string, test: (a:T) => boolean, options?: TraceOptions) => (source$: Observable<T>) => {
84-
const traceSubscription = this.trace$(name, options).subscribe();
87+
traceWhile = <T=any>(name:string, test: (a:T) => boolean, options?: TraceOptions & { orUntilComplete: boolean}) => (source$: Observable<T>) => {
88+
let traceSubscription: Subscription|undefined;
8589
return source$.pipe(
86-
tap(a => { if (!test(a)) { traceSubscription.unsubscribe() }})
90+
tap(
91+
a => {
92+
if (test(a)) {
93+
traceSubscription = traceSubscription || this.trace$(name, options).subscribe();
94+
} else {
95+
traceSubscription && traceSubscription.unsubscribe();
96+
}
97+
},
98+
() => {},
99+
() => options && options.orUntilComplete && traceSubscription && traceSubscription.unsubscribe()
100+
)
87101
)
88102
};
89103

90-
traceUntilLast= <T=any>(name:string, options?: TraceOptions) => (source$: Observable<T>) => {
104+
traceUntilComplete = <T=any>(name:string, options?: TraceOptions) => (source$: Observable<T>) => {
91105
const traceSubscription = this.trace$(name, options).subscribe();
92106
return source$.pipe(
93107
tap(

0 commit comments

Comments
 (0)