forked from hazza/dspace-angular
97732 Remove unnecessary subscriptions
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { Component, OnInit, OnDestroy } from '@angular/core';
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ContextHelpService } from '../../shared/context-help.service';
|
||||
import { Observable, Subscription } from 'rxjs';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
/**
|
||||
@@ -12,22 +12,15 @@ import { map } from 'rxjs/operators';
|
||||
templateUrl: './context-help-toggle.component.html',
|
||||
styleUrls: ['./context-help-toggle.component.scss']
|
||||
})
|
||||
export class ContextHelpToggleComponent implements OnInit, OnDestroy {
|
||||
export class ContextHelpToggleComponent implements OnInit {
|
||||
buttonVisible$: Observable<boolean>;
|
||||
|
||||
constructor(
|
||||
private contextHelpService: ContextHelpService,
|
||||
) { }
|
||||
|
||||
private subs: Subscription[];
|
||||
|
||||
ngOnInit(): void {
|
||||
this.buttonVisible$ = this.contextHelpService.tooltipCount$().pipe(map(x => x > 0));
|
||||
this.subs = [this.buttonVisible$.subscribe()];
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.subs.forEach(sub => sub.unsubscribe());
|
||||
}
|
||||
|
||||
onClick() {
|
||||
|
@@ -61,8 +61,7 @@ export class ContextHelpWrapperComponent implements OnInit, OnDestroy {
|
||||
|
||||
parsedContent$: Observable<ParsedContent>;
|
||||
|
||||
private subs: {always: Subscription[], tooltipBound: Subscription[]}
|
||||
= {always: [], tooltipBound: []};
|
||||
private subs: Subscription[] = [];
|
||||
|
||||
constructor(
|
||||
private translateService: TranslateService,
|
||||
@@ -78,14 +77,13 @@ export class ContextHelpWrapperComponent implements OnInit, OnDestroy {
|
||||
dontParseLinks ? [text] : this.parseLinks(text))
|
||||
);
|
||||
this.shouldShowIcon$ = this.contextHelpService.shouldShowIcons$();
|
||||
this.subs.always = [this.parsedContent$.subscribe(), this.shouldShowIcon$.subscribe()];
|
||||
}
|
||||
|
||||
@ViewChild('tooltip', { static: false }) set setTooltip(tooltip: NgbTooltip) {
|
||||
this.tooltip = tooltip;
|
||||
this.clearSubs('tooltipBound');
|
||||
this.clearSubs();
|
||||
if (this.tooltip !== undefined) {
|
||||
this.subs.tooltipBound = [
|
||||
this.subs = [
|
||||
this.contextHelpService.getContextHelp$(this.id)
|
||||
.pipe(hasValueOperator())
|
||||
.subscribe((ch: ContextHelp) => {
|
||||
@@ -159,13 +157,8 @@ export class ContextHelpWrapperComponent implements OnInit, OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
private clearSubs(filter: null | 'tooltipBound' = null) {
|
||||
if (filter === null) {
|
||||
[].concat(...Object.values(this.subs)).forEach(sub => sub.unsubscribe());
|
||||
this.subs = {always: [], tooltipBound: []};
|
||||
} else {
|
||||
this.subs[filter].forEach(sub => sub.unsubscribe());
|
||||
this.subs[filter] = [];
|
||||
}
|
||||
private clearSubs() {
|
||||
this.subs.forEach(sub => sub.unsubscribe());
|
||||
this.subs = [];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user