From ad870829d2e962c6d259ab74e9c5ee1e8562af48 Mon Sep 17 00:00:00 2001 From: Koen Pauwels Date: Wed, 8 Feb 2023 11:13:03 +0100 Subject: [PATCH] 97732 Remove unnecessary subscriptions --- .../context-help-toggle.component.ts | 13 +++---------- .../context-help-wrapper.component.ts | 19 ++++++------------- 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/src/app/header/context-help-toggle/context-help-toggle.component.ts b/src/app/header/context-help-toggle/context-help-toggle.component.ts index 14f9ebeb63..6685df7106 100644 --- a/src/app/header/context-help-toggle/context-help-toggle.component.ts +++ b/src/app/header/context-help-toggle/context-help-toggle.component.ts @@ -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; 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() { diff --git a/src/app/shared/context-help-wrapper/context-help-wrapper.component.ts b/src/app/shared/context-help-wrapper/context-help-wrapper.component.ts index c5bb40cf1b..e170d522b5 100644 --- a/src/app/shared/context-help-wrapper/context-help-wrapper.component.ts +++ b/src/app/shared/context-help-wrapper/context-help-wrapper.component.ts @@ -61,8 +61,7 @@ export class ContextHelpWrapperComponent implements OnInit, OnDestroy { parsedContent$: Observable; - 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 = []; } }