add missing rxjs unsubscriptions

This commit is contained in:
Mononaut 2025-01-06 18:41:46 +00:00
parent 3c84505579
commit 6553344489
No known key found for this signature in database
GPG key ID: A3F058E41374C04E
5 changed files with 34 additions and 27 deletions

View file

@ -46,6 +46,8 @@ export class AccelerationFeesGraphComponent implements OnInit, OnChanges, OnDest
aggregatedHistory$: Observable<any>; aggregatedHistory$: Observable<any>;
statsSubscription: Subscription; statsSubscription: Subscription;
aggregatedHistorySubscription: Subscription;
fragmentSubscription: Subscription;
isLoading = true; isLoading = true;
formatNumber = formatNumber; formatNumber = formatNumber;
timespan = ''; timespan = '';
@ -79,8 +81,8 @@ export class AccelerationFeesGraphComponent implements OnInit, OnChanges, OnDest
} }
this.radioGroupForm = this.formBuilder.group({ dateSpan: this.miningWindowPreference }); this.radioGroupForm = this.formBuilder.group({ dateSpan: this.miningWindowPreference });
this.radioGroupForm.controls.dateSpan.setValue(this.miningWindowPreference); this.radioGroupForm.controls.dateSpan.setValue(this.miningWindowPreference);
this.route.fragment.subscribe((fragment) => { this.fragmentSubscription = this.route.fragment.subscribe((fragment) => {
if (['24h', '3d', '1w', '1m', '3m', 'all'].indexOf(fragment) > -1) { if (['24h', '3d', '1w', '1m', '3m', 'all'].indexOf(fragment) > -1) {
this.radioGroupForm.controls.dateSpan.setValue(fragment, { emitEvent: false }); this.radioGroupForm.controls.dateSpan.setValue(fragment, { emitEvent: false });
} }
@ -113,7 +115,7 @@ export class AccelerationFeesGraphComponent implements OnInit, OnChanges, OnDest
share(), share(),
); );
this.aggregatedHistory$.subscribe(); this.aggregatedHistorySubscription = this.aggregatedHistory$.subscribe();
} }
ngOnChanges(changes: SimpleChanges): void { ngOnChanges(changes: SimpleChanges): void {
@ -335,8 +337,8 @@ export class AccelerationFeesGraphComponent implements OnInit, OnChanges, OnDest
} }
ngOnDestroy(): void { ngOnDestroy(): void {
if (this.statsSubscription) { this.aggregatedHistorySubscription?.unsubscribe();
this.statsSubscription.unsubscribe(); this.fragmentSubscription?.unsubscribe();
} this.statsSubscription?.unsubscribe();
} }
} }

View file

@ -177,8 +177,9 @@ export class BlockOverviewGraphComponent implements AfterViewInit, OnDestroy, On
if (this.canvas) { if (this.canvas) {
this.canvas.nativeElement.removeEventListener('webglcontextlost', this.handleContextLost); this.canvas.nativeElement.removeEventListener('webglcontextlost', this.handleContextLost);
this.canvas.nativeElement.removeEventListener('webglcontextrestored', this.handleContextRestored); this.canvas.nativeElement.removeEventListener('webglcontextrestored', this.handleContextRestored);
this.themeChangedSubscription?.unsubscribe();
} }
this.themeChangedSubscription?.unsubscribe();
this.searchSubscription?.unsubscribe();
} }
clear(direction): void { clear(direction): void {

View file

@ -116,7 +116,7 @@ export class BlockViewComponent implements OnInit, OnDestroy {
this.isLoadingBlock = false; this.isLoadingBlock = false;
this.isLoadingOverview = true; this.isLoadingOverview = true;
}), }),
shareReplay(1) shareReplay({ bufferSize: 1, refCount: true })
); );
this.overviewSubscription = block$.pipe( this.overviewSubscription = block$.pipe(

View file

@ -117,7 +117,7 @@ export class BlockPreviewComponent implements OnInit, OnDestroy {
this.openGraphService.waitOver('block-data-' + this.rawId); this.openGraphService.waitOver('block-data-' + this.rawId);
}), }),
throttleTime(50, asyncScheduler, { leading: true, trailing: true }), throttleTime(50, asyncScheduler, { leading: true, trailing: true }),
shareReplay(1) shareReplay({ bufferSize: 1, refCount: true })
); );
this.overviewSubscription = block$.pipe( this.overviewSubscription = block$.pipe(

View file

@ -1,8 +1,8 @@
import { Component, OnInit, OnDestroy, ViewChildren, QueryList, ChangeDetectorRef } from '@angular/core'; import { Component, OnInit, OnDestroy, ViewChildren, QueryList, ChangeDetectorRef } from '@angular/core';
import { Location } from '@angular/common'; import { Location } from '@angular/common';
import { ActivatedRoute, ParamMap, Router } from '@angular/router'; import { ActivatedRoute, ParamMap, Params, Router } from '@angular/router';
import { ElectrsApiService } from '@app/services/electrs-api.service'; import { ElectrsApiService } from '@app/services/electrs-api.service';
import { switchMap, tap, throttleTime, catchError, map, shareReplay, startWith, filter } from 'rxjs/operators'; import { switchMap, tap, throttleTime, catchError, map, shareReplay, startWith, filter, take } from 'rxjs/operators';
import { Observable, of, Subscription, asyncScheduler, EMPTY, combineLatest, forkJoin } from 'rxjs'; import { Observable, of, Subscription, asyncScheduler, EMPTY, combineLatest, forkJoin } from 'rxjs';
import { StateService } from '@app/services/state.service'; import { StateService } from '@app/services/state.service';
import { SeoService } from '@app/services/seo.service'; import { SeoService } from '@app/services/seo.service';
@ -68,6 +68,7 @@ export class BlockComponent implements OnInit, OnDestroy {
paginationMaxSize = window.matchMedia('(max-width: 670px)').matches ? 3 : 5; paginationMaxSize = window.matchMedia('(max-width: 670px)').matches ? 3 : 5;
numUnexpected: number = 0; numUnexpected: number = 0;
mode: 'projected' | 'actual' = 'projected'; mode: 'projected' | 'actual' = 'projected';
currentQueryParams: Params;
overviewSubscription: Subscription; overviewSubscription: Subscription;
accelerationsSubscription: Subscription; accelerationsSubscription: Subscription;
@ -80,8 +81,8 @@ export class BlockComponent implements OnInit, OnDestroy {
timeLtr: boolean; timeLtr: boolean;
childChangeSubscription: Subscription; childChangeSubscription: Subscription;
auditPrefSubscription: Subscription; auditPrefSubscription: Subscription;
isAuditEnabledSubscription: Subscription;
oobSubscription: Subscription; oobSubscription: Subscription;
priceSubscription: Subscription; priceSubscription: Subscription;
blockConversion: Price; blockConversion: Price;
@ -118,7 +119,7 @@ export class BlockComponent implements OnInit, OnDestroy {
this.setAuditAvailable(this.auditSupported); this.setAuditAvailable(this.auditSupported);
if (this.auditSupported) { if (this.auditSupported) {
this.isAuditEnabledFromParam().subscribe(auditParam => { this.isAuditEnabledSubscription = this.isAuditEnabledFromParam().subscribe(auditParam => {
if (this.auditParamEnabled) { if (this.auditParamEnabled) {
this.auditModeEnabled = auditParam; this.auditModeEnabled = auditParam;
} else { } else {
@ -281,7 +282,7 @@ export class BlockComponent implements OnInit, OnDestroy {
} }
}), }),
throttleTime(300, asyncScheduler, { leading: true, trailing: true }), throttleTime(300, asyncScheduler, { leading: true, trailing: true }),
shareReplay(1) shareReplay({ bufferSize: 1, refCount: true })
); );
this.overviewSubscription = this.block$.pipe( this.overviewSubscription = this.block$.pipe(
@ -363,6 +364,7 @@ export class BlockComponent implements OnInit, OnDestroy {
.subscribe((network) => this.network = network); .subscribe((network) => this.network = network);
this.queryParamsSubscription = this.route.queryParams.subscribe((params) => { this.queryParamsSubscription = this.route.queryParams.subscribe((params) => {
this.currentQueryParams = params;
if (params.showDetails === 'true') { if (params.showDetails === 'true') {
this.showDetails = true; this.showDetails = true;
} else { } else {
@ -414,6 +416,7 @@ export class BlockComponent implements OnInit, OnDestroy {
ngOnDestroy(): void { ngOnDestroy(): void {
this.stateService.markBlock$.next({}); this.stateService.markBlock$.next({});
this.overviewSubscription?.unsubscribe(); this.overviewSubscription?.unsubscribe();
this.accelerationsSubscription?.unsubscribe();
this.keyNavigationSubscription?.unsubscribe(); this.keyNavigationSubscription?.unsubscribe();
this.blocksSubscription?.unsubscribe(); this.blocksSubscription?.unsubscribe();
this.cacheBlocksSubscription?.unsubscribe(); this.cacheBlocksSubscription?.unsubscribe();
@ -421,8 +424,10 @@ export class BlockComponent implements OnInit, OnDestroy {
this.queryParamsSubscription?.unsubscribe(); this.queryParamsSubscription?.unsubscribe();
this.timeLtrSubscription?.unsubscribe(); this.timeLtrSubscription?.unsubscribe();
this.childChangeSubscription?.unsubscribe(); this.childChangeSubscription?.unsubscribe();
this.priceSubscription?.unsubscribe(); this.auditPrefSubscription?.unsubscribe();
this.isAuditEnabledSubscription?.unsubscribe();
this.oobSubscription?.unsubscribe(); this.oobSubscription?.unsubscribe();
this.priceSubscription?.unsubscribe();
} }
// TODO - Refactor this.fees/this.reward for liquid because it is not // TODO - Refactor this.fees/this.reward for liquid because it is not
@ -733,19 +738,18 @@ export class BlockComponent implements OnInit, OnDestroy {
toggleAuditMode(): void { toggleAuditMode(): void {
this.stateService.hideAudit.next(this.auditModeEnabled); this.stateService.hideAudit.next(this.auditModeEnabled);
this.route.queryParams.subscribe(params => { const queryParams = { ...this.currentQueryParams };
const queryParams = { ...params }; delete queryParams['audit'];
delete queryParams['audit'];
let newUrl = this.router.url.split('?')[0]; let newUrl = this.router.url.split('?')[0];
const queryString = new URLSearchParams(queryParams).toString(); const queryString = new URLSearchParams(queryParams).toString();
if (queryString) { if (queryString) {
newUrl += '?' + queryString; newUrl += '?' + queryString;
} }
this.location.replaceState(newUrl);
this.location.replaceState(newUrl);
});
// avoid duplicate subscriptions
this.auditPrefSubscription?.unsubscribe();
this.auditPrefSubscription = this.stateService.hideAudit.subscribe((hide) => { this.auditPrefSubscription = this.stateService.hideAudit.subscribe((hide) => {
this.auditModeEnabled = !hide; this.auditModeEnabled = !hide;
this.showAudit = this.auditAvailable && this.auditModeEnabled; this.showAudit = this.auditAvailable && this.auditModeEnabled;
@ -762,7 +766,7 @@ export class BlockComponent implements OnInit, OnDestroy {
return this.route.queryParams.pipe( return this.route.queryParams.pipe(
map(params => { map(params => {
this.auditParamEnabled = 'audit' in params; this.auditParamEnabled = 'audit' in params;
return this.auditParamEnabled ? !(params['audit'] === 'false') : true; return this.auditParamEnabled ? !(params['audit'] === 'false') : true;
}) })
); );