Skip to content

Commit d6cfe16

Browse files
authored
feat(multiple): Minor additions (#2921)
* Increase the accuracy of performance marks, by leaning on Zone's start marker * Add automatic transfer state support to the getDownloadURL pipe * Storage.child type fix
1 parent 3277cf2 commit d6cfe16

File tree

4 files changed

+18
-19
lines changed

4 files changed

+18
-19
lines changed

src/compat/performance/performance.service.ts

+2-13
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,16 @@ import { ApplicationRef, Injectable, OnDestroy } from '@angular/core';
22
import { Subscription } from 'rxjs';
33
import { first, tap } from 'rxjs/operators';
44

5-
const IS_STABLE_START_MARK = '_isStableStart';
5+
const IS_STABLE_START_MARK = 'Zone';
66
const IS_STABLE_END_MARK = '_isStableEnd';
77

8-
function markStarts() {
9-
if (typeof(window) !== 'undefined' && window.performance && window.performance.mark) {
10-
window.performance.mark(IS_STABLE_START_MARK);
11-
return true;
12-
} else {
13-
return false;
14-
}
15-
}
16-
17-
const started = markStarts();
18-
198
@Injectable()
209
export class PerformanceMonitoringService implements OnDestroy {
2110

2211
private disposable: Subscription|undefined;
2312

2413
constructor(appRef: ApplicationRef) {
25-
if (started && window.performance.mark) {
14+
if (typeof window !== 'undefined' && window.performance?.mark) {
2615
this.disposable = appRef.isStable.pipe(
2716
first(it => it),
2817
tap(() => {

src/compat/performance/performance.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class AngularFirePerformance {
5252
}
5353

5454
const trace$ = (traceId: string) => {
55-
if (typeof window !== 'undefined' && window.performance && window.performance.mark) {
55+
if (typeof window !== 'undefined' && window.performance?.mark) {
5656
const entries = window.performance.getEntriesByName(traceId, 'measure') || [];
5757
const startMarkName = `_${traceId}Start[${entries.length}]`;
5858
const endMarkName = `_${traceId}End[${entries.length}]`;

src/compat/storage/pipes/storageUrl.pipe.ts

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { AsyncPipe } from '@angular/common';
2-
import { ChangeDetectorRef, NgModule, OnDestroy, Pipe, PipeTransform } from '@angular/core';
3-
import { Observable } from 'rxjs';
2+
import { ChangeDetectorRef, NgModule, OnDestroy, Optional, Pipe, PipeTransform } from '@angular/core';
3+
import { makeStateKey, TransferState } from '@angular/platform-browser';
4+
import { Observable, of } from 'rxjs';
5+
import { tap } from 'rxjs/operators';
46
import { AngularFireStorage } from '../storage';
57

68
/** to be used with in combination with | async */
@@ -14,14 +16,22 @@ export class GetDownloadURLPipe implements PipeTransform, OnDestroy {
1416
private path: string;
1517
private downloadUrl$: Observable<any>;
1618

17-
constructor(private storage: AngularFireStorage, cdr: ChangeDetectorRef) {
19+
constructor(
20+
private storage: AngularFireStorage,
21+
cdr: ChangeDetectorRef,
22+
@Optional() private state: TransferState
23+
) {
1824
this.asyncPipe = new AsyncPipe(cdr);
1925
}
2026

2127
transform(path: string) {
2228
if (path !== this.path) {
2329
this.path = path;
24-
this.downloadUrl$ = this.storage.ref(path).getDownloadURL();
30+
const key = makeStateKey<string>(`|getDownloadURL|${path}`);
31+
const existing = this.state?.get(key, undefined);
32+
this.downloadUrl$ = existing ? of(existing) : this.storage.ref(path).getDownloadURL().pipe(
33+
tap(it => this.state?.set(key, it))
34+
);
2535
}
2636
return this.asyncPipe.transform(this.downloadUrl$);
2737
}

src/compat/storage/ref.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface AngularFireStorageReference {
88
getDownloadURL(): Observable<any>;
99
getMetadata(): Observable<any>;
1010
delete(): Observable<any>;
11-
child(path: string): any;
11+
child(path: string): AngularFireStorageReference;
1212
updateMetadata(meta: SettableMetadata): Observable<any>;
1313
put(data: any, metadata?: UploadMetadata | undefined): AngularFireUploadTask;
1414
putString(data: string, format?: string | undefined, metadata?: UploadMetadata | undefined): AngularFireUploadTask;

0 commit comments

Comments
 (0)