From 94cb910ddfbef8c3a5729884282789738a689d57 Mon Sep 17 00:00:00 2001 From: James Daniels Date: Thu, 2 Sep 2021 02:48:01 -0400 Subject: [PATCH 1/4] Minor perf and storage fix --- src/compat/performance/performance.service.ts | 2 +- src/compat/storage/ref.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compat/performance/performance.service.ts b/src/compat/performance/performance.service.ts index 94c532884..d8fd6a619 100644 --- a/src/compat/performance/performance.service.ts +++ b/src/compat/performance/performance.service.ts @@ -2,7 +2,7 @@ import { ApplicationRef, Injectable, OnDestroy } from '@angular/core'; import { Subscription } from 'rxjs'; import { first, tap } from 'rxjs/operators'; -const IS_STABLE_START_MARK = '_isStableStart'; +const IS_STABLE_START_MARK = 'Zone'; const IS_STABLE_END_MARK = '_isStableEnd'; function markStarts() { diff --git a/src/compat/storage/ref.ts b/src/compat/storage/ref.ts index ecb04ae04..913a0dd57 100644 --- a/src/compat/storage/ref.ts +++ b/src/compat/storage/ref.ts @@ -8,7 +8,7 @@ export interface AngularFireStorageReference { getDownloadURL(): Observable; getMetadata(): Observable; delete(): Observable; - child(path: string): any; + child(path: string): AngularFireStorageReference; updateMetadata(meta: SettableMetadata): Observable; put(data: any, metadata?: UploadMetadata | undefined): AngularFireUploadTask; putString(data: string, format?: string | undefined, metadata?: UploadMetadata | undefined): AngularFireUploadTask; From f1fe1d7128c0bc33cda2b18e8907efb9da56e599 Mon Sep 17 00:00:00 2001 From: James Daniels Date: Thu, 2 Sep 2021 02:51:46 -0400 Subject: [PATCH 2/4] Add state trasnfer to storageUrl --- src/compat/storage/pipes/storageUrl.pipe.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/compat/storage/pipes/storageUrl.pipe.ts b/src/compat/storage/pipes/storageUrl.pipe.ts index 1aaf2caeb..50027ab7d 100644 --- a/src/compat/storage/pipes/storageUrl.pipe.ts +++ b/src/compat/storage/pipes/storageUrl.pipe.ts @@ -1,6 +1,8 @@ import { AsyncPipe } from '@angular/common'; import { ChangeDetectorRef, NgModule, OnDestroy, Pipe, PipeTransform } from '@angular/core'; -import { Observable } from 'rxjs'; +import { makeStateKey, TransferState } from '@angular/platform-browser'; +import { Observable, of } from 'rxjs'; +import { tap } from 'rxjs/operators'; import { AngularFireStorage } from '../storage'; /** to be used with in combination with | async */ @@ -14,14 +16,18 @@ export class GetDownloadURLPipe implements PipeTransform, OnDestroy { private path: string; private downloadUrl$: Observable; - constructor(private storage: AngularFireStorage, cdr: ChangeDetectorRef) { + constructor(private storage: AngularFireStorage, cdr: ChangeDetectorRef, private state: TransferState) { this.asyncPipe = new AsyncPipe(cdr); } transform(path: string) { if (path !== this.path) { this.path = path; - this.downloadUrl$ = this.storage.ref(path).getDownloadURL(); + const key = makeStateKey(`|getDownloadURL|${path}`); + const existing = this.state.get(key, undefined); + this.downloadUrl$ = existing ? of(existing) : this.storage.ref(path).getDownloadURL().pipe( + tap(it => this.state.set(key, it)) + ); } return this.asyncPipe.transform(this.downloadUrl$); } From f02e1bae215e39bee0e1707db8f776ec0deaf779 Mon Sep 17 00:00:00 2001 From: James Daniels Date: Sat, 11 Sep 2021 00:26:06 -0400 Subject: [PATCH 3/4] TransferState is optional --- src/compat/storage/pipes/storageUrl.pipe.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/compat/storage/pipes/storageUrl.pipe.ts b/src/compat/storage/pipes/storageUrl.pipe.ts index 50027ab7d..5f20d2fd4 100644 --- a/src/compat/storage/pipes/storageUrl.pipe.ts +++ b/src/compat/storage/pipes/storageUrl.pipe.ts @@ -1,5 +1,5 @@ import { AsyncPipe } from '@angular/common'; -import { ChangeDetectorRef, NgModule, OnDestroy, Pipe, PipeTransform } from '@angular/core'; +import { ChangeDetectorRef, NgModule, OnDestroy, Optional, Pipe, PipeTransform } from '@angular/core'; import { makeStateKey, TransferState } from '@angular/platform-browser'; import { Observable, of } from 'rxjs'; import { tap } from 'rxjs/operators'; @@ -16,7 +16,11 @@ export class GetDownloadURLPipe implements PipeTransform, OnDestroy { private path: string; private downloadUrl$: Observable; - constructor(private storage: AngularFireStorage, cdr: ChangeDetectorRef, private state: TransferState) { + constructor( + private storage: AngularFireStorage, + cdr: ChangeDetectorRef, + @Optional() private state: TransferState + ) { this.asyncPipe = new AsyncPipe(cdr); } @@ -24,9 +28,9 @@ export class GetDownloadURLPipe implements PipeTransform, OnDestroy { if (path !== this.path) { this.path = path; const key = makeStateKey(`|getDownloadURL|${path}`); - const existing = this.state.get(key, undefined); + const existing = this.state?.get(key, undefined); this.downloadUrl$ = existing ? of(existing) : this.storage.ref(path).getDownloadURL().pipe( - tap(it => this.state.set(key, it)) + tap(it => this.state?.set(key, it)) ); } return this.asyncPipe.transform(this.downloadUrl$); From 6b4af19deee9ddafb00917f2ef5543bde9eaee88 Mon Sep 17 00:00:00 2001 From: James Daniels Date: Sat, 11 Sep 2021 00:31:49 -0400 Subject: [PATCH 4/4] Don't mark start, better typecheck --- src/compat/performance/performance.service.ts | 13 +------------ src/compat/performance/performance.ts | 2 +- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/src/compat/performance/performance.service.ts b/src/compat/performance/performance.service.ts index 7cbcb7085..5510f8087 100644 --- a/src/compat/performance/performance.service.ts +++ b/src/compat/performance/performance.service.ts @@ -5,24 +5,13 @@ import { first, tap } from 'rxjs/operators'; const IS_STABLE_START_MARK = 'Zone'; const IS_STABLE_END_MARK = '_isStableEnd'; -function markStarts() { - if (typeof(window) !== 'undefined' && window.performance && window.performance.mark) { - window.performance.mark(IS_STABLE_START_MARK); - return true; - } else { - return false; - } -} - -const started = markStarts(); - @Injectable() export class PerformanceMonitoringService implements OnDestroy { private disposable: Subscription|undefined; constructor(appRef: ApplicationRef) { - if (started && window.performance.mark) { + if (typeof window !== 'undefined' && window.performance?.mark) { this.disposable = appRef.isStable.pipe( first(it => it), tap(() => { diff --git a/src/compat/performance/performance.ts b/src/compat/performance/performance.ts index b9b083f19..5bc217509 100644 --- a/src/compat/performance/performance.ts +++ b/src/compat/performance/performance.ts @@ -52,7 +52,7 @@ export class AngularFirePerformance { } const trace$ = (traceId: string) => { - if (typeof window !== 'undefined' && window.performance && window.performance.mark) { + if (typeof window !== 'undefined' && window.performance?.mark) { const entries = window.performance.getEntriesByName(traceId, 'measure') || []; const startMarkName = `_${traceId}Start[${entries.length}]`; const endMarkName = `_${traceId}End[${entries.length}]`;