From 1b25ce9e083f3ee6acc8d7f8438ea0d3828ba40f Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Wed, 26 Feb 2020 16:59:46 -0500 Subject: [PATCH] clean up router event subscription Signed-off-by: Galen Charlton --- .../src/app/staff/acq/search/acq-search.component.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.component.ts b/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.component.ts index fca4c6afa6..43e3edbde1 100644 --- a/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/acq/search/acq-search.component.ts @@ -1,6 +1,8 @@ -import {Component, OnInit, AfterViewInit, ViewChild, ViewChildren, QueryList} from '@angular/core'; +import {Component, OnInit, AfterViewInit, ViewChild, ViewChildren, QueryList, OnDestroy} from '@angular/core'; import {NgbTabset, NgbTabChangeEvent} from '@ng-bootstrap/ng-bootstrap'; -import {Router, ActivatedRoute, ParamMap, NavigationEnd} from '@angular/router'; +import {Router, ActivatedRoute, ParamMap, RouterEvent, NavigationEnd} from '@angular/router'; +import {filter, takeUntil} from 'rxjs/operators'; +import {Subject} from 'rxjs'; import {StaffCommonModule} from '@eg/staff/common.module'; import {IdlService, IdlObject} from '@eg/core/idl.service'; import {PcrudService} from '@eg/core/pcrud.service'; @@ -14,7 +16,7 @@ import {PicklistResultsComponent} from './picklist-results.component'; templateUrl: './acq-search.component.html' }) -export class AcqSearchComponent implements OnInit, AfterViewInit { +export class AcqSearchComponent implements OnInit, AfterViewInit, OnDestroy { searchType = ''; validSearchTypes = ['lineitems', 'purchaseorders', 'invoices', 'selectionlists']; @@ -30,6 +32,7 @@ export class AcqSearchComponent implements OnInit, AfterViewInit { @ViewChildren(PicklistResultsComponent) plResults: QueryList; previousUrl: string = null; + public destroyed = new Subject(); constructor( private router: Router, @@ -69,7 +72,10 @@ export class AcqSearchComponent implements OnInit, AfterViewInit { this.ngOnInit(); // TODO: probably overkill }); }); - this.router.events.subscribe(routeEvent => { + this.router.events.pipe( + filter((event: RouterEvent) => event instanceof NavigationEnd), + takeUntil(this.destroyed) + ).subscribe(routeEvent => { if (routeEvent instanceof NavigationEnd) { // force reset of grid data source if we're navigating from // a search tab to the same search tab @@ -126,4 +132,9 @@ export class AcqSearchComponent implements OnInit, AfterViewInit { ngAfterViewInit() {} + ngOnDestroy(): void { + this.destroyed.next(); + this.destroyed.complete(); + } + } -- 2.11.0