1
0

97732 Remove unnecessary subscriptions

This commit is contained in:
Koen Pauwels
2023-02-08 11:13:03 +01:00
parent ac5a359b1d
commit ad870829d2
2 changed files with 9 additions and 23 deletions

View File

@@ -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() {

View File

@@ -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 = [];
}
}