Skip to content

Commit

Permalink
fix(epsilon-tab): avoid null result during recalculation
Browse files Browse the repository at this point in the history
  • Loading branch information
ducktordanny committed Sep 18, 2022
1 parent 2cdc205 commit de374f6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('EpsilonTabComponent', () => {
expect(component.secondStepFormGroup.getRawValue()).toEqual({});
expect(component.costs$.getValue()).toEqual(costsMock);
expect(component.transportations$.getValue()).toEqual(transportationsMock);
expect(component.result$).toEqual(null);
expect(component.result$.getValue()).toEqual(null);
component.isLoading$.subscribe((loading: boolean) =>
expect(loading).toEqual(false),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ import {Epsilon, Table, TransportTable} from '@opres/shared/types';
import {InputTableService} from '@opres/ui/tables';
import {LanguageSwitcherService} from '@frontend/components/layout/language-switcher/language-switcher.service';
import {LoadingHandlerService} from '@frontend/services/loading-handler.service';
import {UntilDestroy, untilDestroyed} from '@ngneat/until-destroy';
import {forEach, mapValues} from 'lodash';
import {BehaviorSubject, Observable} from 'rxjs';
import {finalize} from 'rxjs/operators';
import {BehaviorSubject} from 'rxjs';
import {finalize, tap} from 'rxjs/operators';

import {
transportProblemCacheBuster$,
TransportProblemService,
} from '../../transport-problem.service';

@UntilDestroy()
@Component({
selector: 'epsilon-tab',
templateUrl: './epsilon.tab.template.html',
Expand All @@ -37,7 +39,7 @@ export class EpsilonTabComponent {
]);
public isLoading$ = this.loadingHandler.isLoading;
public currentLanguage$ = this.languageSwitcherService.currentLanguage;
public result$: Observable<Epsilon> | null = null;
public result$ = new BehaviorSubject<Epsilon | null>(null);

constructor(
private transportProblemService: TransportProblemService,
Expand Down Expand Up @@ -75,9 +77,14 @@ export class EpsilonTabComponent {
public onCalculate(): void {
this.loadingHandler.start();
const transportTable = this.getTransportTableFromCurrentInput();
this.result$ = this.transportProblemService
this.transportProblemService
.getEpsilonResult(transportTable)
.pipe(finalize(() => this.loadingHandler.stop()));
.pipe(
tap((response) => this.result$.next(response)),
finalize(() => this.loadingHandler.stop()),
untilDestroyed(this),
)
.subscribe();
}

private getTransportTableFromCurrentInput(): TransportTable {
Expand Down

0 comments on commit de374f6

Please sign in to comment.