Browse Source

fix(client): prevent race condition of nested subscriptions

pull/7076/head
KenTandrian 4 weeks ago
parent
commit
b761d82d50
  1. 30
      apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts

30
apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts

@ -43,6 +43,7 @@ import {
} from '@prisma/client';
import { isNumber } from 'lodash';
import { DeviceDetectorService } from 'ngx-device-detector';
import { filter, switchMap, tap } from 'rxjs';
import { AllocationsPageParams } from './interfaces/interfaces';
@ -161,31 +162,30 @@ export class GfAllocationsPageComponent implements OnInit {
});
this.userService.stateChanged
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((state) => {
if (state?.user) {
.pipe(
filter((state) => !!state?.user),
tap((state) => {
this.user = state.user;
this.isLoading = true;
this.initialize();
this.fetchPortfolioDetails()
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((portfolioDetails) => {
this.initialize();
this.portfolioDetails = portfolioDetails;
this.changeDetectorRef.markForCheck();
}),
switchMap(() => this.fetchPortfolioDetails()),
takeUntilDestroyed(this.destroyRef)
)
.subscribe((portfolioDetails) => {
this.initialize();
this.initializeAllocationsData();
this.portfolioDetails = portfolioDetails;
this.isLoading = false;
this.initializeAllocationsData();
this.changeDetectorRef.markForCheck();
});
this.isLoading = false;
this.changeDetectorRef.markForCheck();
}
this.changeDetectorRef.markForCheck();
});
this.initialize();

Loading…
Cancel
Save