Skip to content

Commit 744cd5c

Browse files
SkyZeroZxatscott
authored andcommitted
refactor(http): simplifies destruction tracking using destroyed property
Replaces the manual destroyed state with destroyed property (cherry picked from commit 44435ea)
1 parent a45e6b2 commit 744cd5c

File tree

2 files changed

+1
-9
lines changed

2 files changed

+1
-9
lines changed

goldens/public-api/common/http/index.api.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { WritableResource } from '@angular/core';
1919

2020
// @public
2121
export class FetchBackend implements HttpBackend {
22-
constructor();
2322
// (undocumented)
2423
handle(request: HttpRequest<any>): Observable<HttpEvent<any>>;
2524
// (undocumented)

packages/common/http/src/fetch.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,6 @@ export class FetchBackend implements HttpBackend {
8282
inject(FetchFactory, {optional: true})?.fetch ?? ((...args) => globalThis.fetch(...args));
8383
private readonly ngZone = inject(NgZone);
8484
private readonly destroyRef = inject(DestroyRef);
85-
private destroyed = false;
86-
87-
constructor() {
88-
this.destroyRef.onDestroy(() => {
89-
this.destroyed = true;
90-
});
91-
}
9285

9386
handle(request: HttpRequest<any>): Observable<HttpEvent<any>> {
9487
return new Observable((observer) => {
@@ -193,7 +186,7 @@ export class FetchBackend implements HttpBackend {
193186
// unnecessary work or triggering side effects after teardown.
194187
// This may happen if the app was explicitly destroyed before
195188
// the response returned entirely.
196-
if (this.destroyed) {
189+
if (this.destroyRef.destroyed) {
197190
// Streams left in a pending state (due to `break` without cancel) may
198191
// continue consuming or holding onto data behind the scenes.
199192
// Calling `reader.cancel()` allows the browser or the underlying

0 commit comments

Comments
 (0)