Unsubscribe subscriptions

This commit is contained in:
Giuseppe Digilio
2019-02-18 16:50:43 +01:00
parent 18eaef3c2b
commit 3ba018cd33
2 changed files with 12 additions and 10 deletions

View File

@@ -44,7 +44,7 @@ export class DsDynamicLookupComponent extends DynamicFormControlComponent implem
public optionsList: any; public optionsList: any;
protected searchOptions: IntegrationSearchOptions; protected searchOptions: IntegrationSearchOptions;
protected sub: Subscription; protected subs: Subscription[] = [];
constructor(private authorityService: AuthorityService, constructor(private authorityService: AuthorityService,
private cdr: ChangeDetectorRef, private cdr: ChangeDetectorRef,
@@ -69,14 +69,14 @@ export class DsDynamicLookupComponent extends DynamicFormControlComponent implem
this.setInputsValue(this.model.value); this.setInputsValue(this.model.value);
this.model.valueUpdates this.subs.push(this.model.valueUpdates
.subscribe((value) => { .subscribe((value) => {
if (isEmpty(value)) { if (isEmpty(value)) {
this.resetFields(); this.resetFields();
} else if (!this.editMode) { } else if (!this.editMode) {
this.setInputsValue(this.model.value); this.setInputsValue(this.model.value);
} }
}); }));
} }
protected getCurrentValue(): string { protected getCurrentValue(): string {
@@ -234,7 +234,7 @@ export class DsDynamicLookupComponent extends DynamicFormControlComponent implem
this.searchOptions.query = this.getCurrentValue(); this.searchOptions.query = this.getCurrentValue();
this.loading = true; this.loading = true;
this.authorityService.getEntriesByName(this.searchOptions).pipe( this.subs.push(this.authorityService.getEntriesByName(this.searchOptions).pipe(
catchError(() => { catchError(() => {
const emptyResult = new IntegrationData( const emptyResult = new IntegrationData(
new PageInfo(), new PageInfo(),
@@ -248,7 +248,7 @@ export class DsDynamicLookupComponent extends DynamicFormControlComponent implem
this.pageInfo = object.pageInfo; this.pageInfo = object.pageInfo;
this.loading = false; this.loading = false;
this.cdr.detectChanges(); this.cdr.detectChanges();
}); }));
} }
public switchEditMode() { public switchEditMode() {
@@ -263,8 +263,8 @@ export class DsDynamicLookupComponent extends DynamicFormControlComponent implem
} }
ngOnDestroy() { ngOnDestroy() {
if (hasValue(this.sub)) { this.subs
this.sub.unsubscribe(); .filter((sub) => hasValue(sub))
} .forEach((sub) => sub.unsubscribe());
} }
} }

View File

@@ -1,7 +1,7 @@
import { Component, Input, OnChanges } from '@angular/core'; import { Component, Input, OnChanges } from '@angular/core';
import { TranslateService } from '@ngx-translate/core'; import { TranslateService } from '@ngx-translate/core';
import { Observable, of as observableOf } from 'rxjs'; import { Observable, of as observableOf, Subscription } from 'rxjs';
import { first } from 'rxjs/operators'; import { first } from 'rxjs/operators';
import { SectionsService } from '../../sections/sections.service'; import { SectionsService } from '../../sections/sections.service';
@@ -33,11 +33,13 @@ export class SubmissionUploadFilesComponent implements OnChanges {
private uploadEnabled: Observable<boolean> = observableOf(false); private uploadEnabled: Observable<boolean> = observableOf(false);
public onBeforeUpload = () => { public onBeforeUpload = () => {
this.operationsService.jsonPatchByResourceType( const sub: Subscription = this.operationsService.jsonPatchByResourceType(
this.submissionService.getSubmissionObjectLinkName(), this.submissionService.getSubmissionObjectLinkName(),
this.submissionId, this.submissionId,
'sections') 'sections')
.subscribe(); .subscribe();
this.subs.push(sub);
return sub;
}; };
constructor(private notificationsService: NotificationsService, constructor(private notificationsService: NotificationsService,