Skip to content

Commit

Permalink
add destroy observable to stop subscription of reloadKeySubject
Browse files Browse the repository at this point in the history
  • Loading branch information
nevio18324 authored and peggimann committed Oct 23, 2024
1 parent f9db625 commit 123f6f5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "2.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve ",
"start": "ng serve --host 0.0.0.0",
"build": "ng build",
"build:staging": "ng build --configuration staging",
"watch": "ng build --watch --configuration development",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core';
import { ChangeDetectionStrategy, Component, Input, OnDestroy, OnInit } from '@angular/core';
import { KeyResult } from '../../shared/types/model/KeyResult';
import { KeyresultService } from '../../services/keyresult.service';
import { KeyResultMetric } from '../../shared/types/model/KeyResultMetric';
import { KeyResultOrdinal } from '../../shared/types/model/KeyResultOrdinal';
import { CheckInHistoryDialogComponent } from '../check-in-history-dialog/check-in-history-dialog.component';
import { MatDialog } from '@angular/material/dialog';
import { BehaviorSubject, catchError, EMPTY } from 'rxjs';
import { BehaviorSubject, catchError, EMPTY, Subject, takeUntil } from 'rxjs';
import { ActivatedRoute, Router } from '@angular/router';
import { RefreshDataService } from '../../services/refresh-data.service';
import { CloseState } from '../../shared/types/enums/CloseState';
Expand All @@ -22,10 +22,11 @@ import { ConfirmDialogComponent } from '../../shared/dialog/confirm-dialog/confi
styleUrls: ['./keyresult-detail.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class KeyresultDetailComponent implements OnInit {
export class KeyresultDetailComponent implements OnInit, OnDestroy {
@Input() keyResultId!: number;

keyResult$: BehaviorSubject<KeyResult> = new BehaviorSubject<KeyResult>({} as KeyResult);
ngDestroy$: Subject<void> = new Subject();
isComplete: boolean = false;
protected readonly DATE_FORMAT = DATE_FORMAT;
protected readonly isLastCheckInNegative = isLastCheckInNegative;
Expand All @@ -41,11 +42,16 @@ export class KeyresultDetailComponent implements OnInit {
ngOnInit(): void {
this.keyResultId = this.getIdFromParams();
this.loadKeyResult(this.keyResultId);
this.refreshDataService.reloadKeyResultSubject.subscribe(() => {
this.refreshDataService.reloadKeyResultSubject.pipe(takeUntil(this.ngDestroy$)).subscribe(() => {
this.loadKeyResult(this.keyResultId);
});
}

ngOnDestroy() {
this.ngDestroy$.next();
this.ngDestroy$.complete();
}

private getIdFromParams(): number {
const id = this.route.snapshot.paramMap.get('id');
if (!id) {
Expand Down

0 comments on commit 123f6f5

Please sign in to comment.