Browse Source

Task/eliminate OnDestroy lifecycle hook from assistant component (#6673)

Eliminate OnDestroy lifecycle hook
pull/6721/head
Erwin 3 days ago
committed by GitHub
parent
commit
5afceb802c
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 22
      libs/ui/src/lib/assistant/assistant.component.ts

22
libs/ui/src/lib/assistant/assistant.component.ts

@ -11,6 +11,7 @@ import {
ChangeDetectionStrategy, ChangeDetectionStrategy,
ChangeDetectorRef, ChangeDetectorRef,
Component, Component,
DestroyRef,
ElementRef, ElementRef,
HostListener, HostListener,
Input, Input,
@ -22,6 +23,7 @@ import {
ViewChildren, ViewChildren,
output output
} from '@angular/core'; } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms'; import { FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button'; import { MatButtonModule } from '@angular/material/button';
import { MatFormFieldModule } from '@angular/material/form-field'; import { MatFormFieldModule } from '@angular/material/form-field';
@ -40,7 +42,7 @@ import {
} from 'ionicons/icons'; } from 'ionicons/icons';
import { isFunction } from 'lodash'; import { isFunction } from 'lodash';
import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader'; import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader';
import { EMPTY, Observable, Subject, merge, of } from 'rxjs'; import { EMPTY, Observable, merge, of } from 'rxjs';
import { import {
catchError, catchError,
debounceTime, debounceTime,
@ -48,7 +50,6 @@ import {
map, map,
scan, scan,
switchMap, switchMap,
takeUntil,
tap tap
} from 'rxjs/operators'; } from 'rxjs/operators';
@ -146,12 +147,12 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit {
private keyManager: FocusKeyManager<GfAssistantListItemComponent>; private keyManager: FocusKeyManager<GfAssistantListItemComponent>;
private preselectionTimeout: ReturnType<typeof setTimeout>; private preselectionTimeout: ReturnType<typeof setTimeout>;
private unsubscribeSubject = new Subject<void>();
public constructor( public constructor(
private adminService: AdminService, private adminService: AdminService,
private changeDetectorRef: ChangeDetectorRef, private changeDetectorRef: ChangeDetectorRef,
private dataService: DataService private dataService: DataService,
private destroyRef: DestroyRef
) { ) {
addIcons({ closeCircleOutline, closeOutline, searchOutline }); addIcons({ closeCircleOutline, closeOutline, searchOutline });
} }
@ -333,7 +334,7 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit {
) )
); );
}), }),
takeUntil(this.unsubscribeSubject) takeUntilDestroyed(this.destroyRef)
) )
.subscribe({ .subscribe({
next: (searchResults) => { next: (searchResults) => {
@ -477,7 +478,7 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit {
this.dataService this.dataService
.fetchPortfolioHoldings() .fetchPortfolioHoldings()
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(({ holdings }) => { .subscribe(({ holdings }) => {
this.holdings = holdings this.holdings = holdings
.filter(({ assetSubClass }) => { .filter(({ assetSubClass }) => {
@ -556,9 +557,6 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit {
if (this.preselectionTimeout) { if (this.preselectionTimeout) {
clearTimeout(this.preselectionTimeout); clearTimeout(this.preselectionTimeout);
} }
this.unsubscribeSubject.next();
this.unsubscribeSubject.complete();
} }
private getCurrentAssistantListItem() { private getCurrentAssistantListItem() {
@ -643,7 +641,7 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit {
}; };
}); });
}), }),
takeUntil(this.unsubscribeSubject) takeUntilDestroyed(this.destroyRef)
); );
} }
@ -678,7 +676,7 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit {
} }
); );
}), }),
takeUntil(this.unsubscribeSubject) takeUntilDestroyed(this.destroyRef)
); );
} }
@ -710,7 +708,7 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit {
} }
); );
}), }),
takeUntil(this.unsubscribeSubject) takeUntilDestroyed(this.destroyRef)
); );
} }

Loading…
Cancel
Save