Skip to content

Commit 44435ea

Browse files
SkyZeroZxatscott
authored andcommitted
refactor(http): simplifies destruction tracking using destroyed property
Replaces the manual destroyed state with destroyed property
1 parent 31d4127 commit 44435ea

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
@@ -63,13 +63,6 @@ export class FetchBackend implements HttpBackend {
6363
inject(FetchFactory, {optional: true})?.fetch ?? ((...args) => globalThis.fetch(...args));
6464
private readonly ngZone = inject(NgZone);
6565
private readonly destroyRef = inject(DestroyRef);
66-
private destroyed = false;
67-
68-
constructor() {
69-
this.destroyRef.onDestroy(() => {
70-
this.destroyed = true;
71-
});
72-
}
7366

7467
handle(request: HttpRequest<any>): Observable<HttpEvent<any>> {
7568
return new Observable((observer) => {
@@ -174,7 +167,7 @@ export class FetchBackend implements HttpBackend {
174167
// unnecessary work or triggering side effects after teardown.
175168
// This may happen if the app was explicitly destroyed before
176169
// the response returned entirely.
177-
if (this.destroyed) {
170+
if (this.destroyRef.destroyed) {
178171
// Streams left in a pending state (due to `break` without cancel) may
179172
// continue consuming or holding onto data behind the scenes.
180173
// Calling `reader.cancel()` allows the browser or the underlying

0 commit comments

Comments
 (0)