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