Browse Source

Task/eliminate OnDestroy lifecycle hook from markets component (#6592)

* Eliminate OnDestroy lifecycle hook
pull/6609/head
Nathan Nguyen 3 days ago
committed by GitHub
parent
commit
bd4f62ce1a
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 21
      apps/client/src/app/components/markets/markets.component.ts

21
apps/client/src/app/components/markets/markets.component.ts

@ -19,12 +19,11 @@ import {
ChangeDetectorRef, ChangeDetectorRef,
Component, Component,
CUSTOM_ELEMENTS_SCHEMA, CUSTOM_ELEMENTS_SCHEMA,
OnDestroy, DestroyRef,
OnInit OnInit
} from '@angular/core'; } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { DeviceDetectorService } from 'ngx-device-detector'; import { DeviceDetectorService } from 'ngx-device-detector';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
@Component({ @Component({
changeDetection: ChangeDetectionStrategy.OnPush, changeDetection: ChangeDetectionStrategy.OnPush,
@ -39,7 +38,7 @@ import { takeUntil } from 'rxjs/operators';
styleUrls: ['./markets.scss'], styleUrls: ['./markets.scss'],
templateUrl: './markets.html' templateUrl: './markets.html'
}) })
export class GfMarketsComponent implements OnDestroy, OnInit { export class GfMarketsComponent implements OnInit {
public benchmarks: Benchmark[]; public benchmarks: Benchmark[];
public deviceType: string; public deviceType: string;
public fearAndGreedIndex: number; public fearAndGreedIndex: number;
@ -55,18 +54,17 @@ export class GfMarketsComponent implements OnDestroy, OnInit {
public readonly numberOfDays = 365; public readonly numberOfDays = 365;
public user: User; public user: User;
private unsubscribeSubject = new Subject<void>();
public constructor( public constructor(
private changeDetectorRef: ChangeDetectorRef, private changeDetectorRef: ChangeDetectorRef,
private dataService: DataService, private dataService: DataService,
private destroyRef: DestroyRef,
private deviceService: DeviceDetectorService, private deviceService: DeviceDetectorService,
private userService: UserService private userService: UserService
) { ) {
this.deviceType = this.deviceService.getDeviceInfo().deviceType; this.deviceType = this.deviceService.getDeviceInfo().deviceType;
this.userService.stateChanged this.userService.stateChanged
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((state) => { .subscribe((state) => {
if (state?.user) { if (state?.user) {
this.user = state.user; this.user = state.user;
@ -79,7 +77,7 @@ export class GfMarketsComponent implements OnDestroy, OnInit {
public ngOnInit() { public ngOnInit() {
this.dataService this.dataService
.fetchMarketDataOfMarkets({ includeHistoricalData: this.numberOfDays }) .fetchMarketDataOfMarkets({ includeHistoricalData: this.numberOfDays })
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(({ fearAndGreedIndex }) => { .subscribe(({ fearAndGreedIndex }) => {
this.fearAndGreedIndexData = fearAndGreedIndex; this.fearAndGreedIndexData = fearAndGreedIndex;
@ -90,7 +88,7 @@ export class GfMarketsComponent implements OnDestroy, OnInit {
this.dataService this.dataService
.fetchBenchmarks() .fetchBenchmarks()
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(({ benchmarks }) => { .subscribe(({ benchmarks }) => {
this.benchmarks = benchmarks; this.benchmarks = benchmarks;
@ -119,9 +117,4 @@ export class GfMarketsComponent implements OnDestroy, OnInit {
this.initialize(); this.initialize();
} }
public ngOnDestroy() {
this.unsubscribeSubject.next();
this.unsubscribeSubject.complete();
}
} }

Loading…
Cancel
Save