From 69534941461ea56eb65978ac35fa2c042d15e194 Mon Sep 17 00:00:00 2001 From: Ryan Mathis Date: Thu, 14 Feb 2019 14:24:20 -0700 Subject: [PATCH] SHIBUI-1227 Fixed issue with wrong page of editor displaying --- .../resolver/container/resolver-select.component.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/ui/src/app/metadata/resolver/container/resolver-select.component.ts b/ui/src/app/metadata/resolver/container/resolver-select.component.ts index c30396559..041e0e8d2 100644 --- a/ui/src/app/metadata/resolver/container/resolver-select.component.ts +++ b/ui/src/app/metadata/resolver/container/resolver-select.component.ts @@ -1,9 +1,9 @@ import { Component, OnDestroy, Inject } from '@angular/core'; -import { Subscription, Observable } from 'rxjs'; +import { Subscription, Observable, Subject } from 'rxjs'; import { Store } from '@ngrx/store'; import { ActivatedRoute } from '@angular/router'; -import { map, distinctUntilChanged, skipWhile } from 'rxjs/operators'; +import { map, distinctUntilChanged, skipWhile, takeUntil } from 'rxjs/operators'; import { SelectResolver } from '../action/collection.action'; import * as fromResolvers from '../reducer'; import { MetadataResolver } from '../../domain/model'; @@ -19,6 +19,7 @@ import { Wizard } from '../../../wizard/model'; }) export class ResolverSelectComponent implements OnDestroy { + private ngUnsubscribe: Subject = new Subject(); actionsSubscription: Subscription; resolver$: Observable; @@ -28,13 +29,14 @@ export class ResolverSelectComponent implements OnDestroy { private route: ActivatedRoute, @Inject(METADATA_SOURCE_EDITOR) private sourceWizard: Wizard ) { - this.actionsSubscription = this.route.params.pipe( + this.route.params.pipe( + takeUntil(this.ngUnsubscribe), map(params => new SelectResolver(params.id)) ).subscribe(store); this.resolver$ = this.store.select(fromResolvers.getSelectedResolver).pipe(skipWhile(p => !p)); - this.resolver$.subscribe(resolver => this.setDefinition(resolver)); + this.resolver$.pipe(takeUntil(this.ngUnsubscribe)).subscribe(resolver => this.setDefinition(resolver)); } setDefinition(resolver: MetadataResolver): void { @@ -44,7 +46,8 @@ export class ResolverSelectComponent implements OnDestroy { } ngOnDestroy() { - this.actionsSubscription.unsubscribe(); + this.ngUnsubscribe.next(); + this.ngUnsubscribe.complete(); this.store.dispatch(new Clear()); this.store.dispatch(new ClearWizard()); }