Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

Task/eliminate OnDestroy lifecycle hook from home overview component (#6549)

Erwin9f9008c89a37
diff --git a/apps/client/src/app/components/home-overview/home-overview.component.ts b/apps/client/src/app/components/home-overview/home-overview.component.ts
index cb1df1a741..58284d27de 100644
--- a/apps/client/src/app/components/home-overview/home-overview.component.ts
+++ b/apps/client/src/app/components/home-overview/home-overview.component.ts
@@ -19,14 +19,13 @@ import {
ChangeDetectorRef,
Component,
CUSTOM_ELEMENTS_SCHEMA,
- OnDestroy,
+ DestroyRef,
OnInit
} from '@angular/core';
+import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { MatButtonModule } from '@angular/material/button';
import { RouterModule } from '@angular/router';
import { DeviceDetectorService } from 'ngx-device-detector';
-import { Subject } from 'rxjs';
-import { takeUntil } from 'rxjs/operators';
@Component({
imports: [
@@ -41,7 +40,7 @@ import { takeUntil } from 'rxjs/operators';
styleUrls: ['./home-overview.scss'],
templateUrl: './home-overview.html'
})
-export class GfHomeOverviewComponent implements OnDestroy, OnInit {
+export class GfHomeOverviewComponent implements OnInit {
public deviceType: string;
public errors: AssetProfileIdentifier[];
public hasError: boolean;
@@ -62,18 +61,17 @@ export class GfHomeOverviewComponent implements OnDestroy, OnInit {
public unit: string;
public user: User;
- private unsubscribeSubject = new Subject<void>();
-
public constructor(
private changeDetectorRef: ChangeDetectorRef,
private dataService: DataService,
+ private destroyRef: DestroyRef,
private deviceService: DeviceDetectorService,
private impersonationStorageService: ImpersonationStorageService,
private layoutService: LayoutService,
private userService: UserService
) {
this.userService.stateChanged
- .pipe(takeUntil(this.unsubscribeSubject))
+ .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((state) => {
if (state?.user) {
this.user = state.user;
@@ -99,7 +97,7 @@ export class GfHomeOverviewComponent implements OnDestroy, OnInit {
this.impersonationStorageService
.onChangeHasImpersonation()
- .pipe(takeUntil(this.unsubscribeSubject))
+ .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((impersonationId) => {
this.hasImpersonationId = !!impersonationId;
@@ -107,17 +105,12 @@ export class GfHomeOverviewComponent implements OnDestroy, OnInit {
});
this.layoutService.shouldReloadContent$
- .pipe(takeUntil(this.unsubscribeSubject))
+ .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(() => {
this.update();
});
}
- public ngOnDestroy() {
- this.unsubscribeSubject.next();
- this.unsubscribeSubject.complete();
- }
-
private update() {
this.historicalDataItems = null;
this.isLoadingPerformance = true;
@@ -126,7 +119,7 @@ export class GfHomeOverviewComponent implements OnDestroy, OnInit {
.fetchPortfolioPerformance({
range: this.user?.settings?.dateRange
})
- .pipe(takeUntil(this.unsubscribeSubject))
+ .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(({ chart, errors, performance }) => {
this.errors = errors;
this.performance = performance;