|
1 | 1 | import { Injectable, NgZone, ApplicationRef, InjectionToken, Inject, Optional } from '@angular/core';
|
2 |
| -import { Observable } from 'rxjs'; |
| 2 | +import { Observable, Subscription } from 'rxjs'; |
3 | 3 | import { first, tap } from 'rxjs/operators';
|
4 | 4 | import { performance } from 'firebase/app';
|
5 | 5 |
|
@@ -37,7 +37,7 @@ export class AngularFirePerformance {
|
37 | 37 |
|
38 | 38 | // TODO determine more built in metrics
|
39 | 39 | appRef.isStable.pipe(
|
40 |
| - this.traceUntilLast('isStable'), |
| 40 | + this.traceUntilComplete('isStable'), |
41 | 41 | first(it => it)
|
42 | 42 | ).subscribe();
|
43 | 43 |
|
@@ -73,21 +73,35 @@ export class AngularFirePerformance {
|
73 | 73 | })
|
74 | 74 | );
|
75 | 75 |
|
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>) => { |
77 | 77 | const traceSubscription = this.trace$(name, options).subscribe();
|
78 | 78 | 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 | + ) |
80 | 84 | )
|
81 | 85 | };
|
82 | 86 |
|
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; |
85 | 89 | 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 | + ) |
87 | 101 | )
|
88 | 102 | };
|
89 | 103 |
|
90 |
| - traceUntilLast= <T=any>(name:string, options?: TraceOptions) => (source$: Observable<T>) => { |
| 104 | + traceUntilComplete = <T=any>(name:string, options?: TraceOptions) => (source$: Observable<T>) => { |
91 | 105 | const traceSubscription = this.trace$(name, options).subscribe();
|
92 | 106 | return source$.pipe(
|
93 | 107 | tap(
|
|
0 commit comments