Browse Source

fix(client): prevent race condition of nested subscriptions

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

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

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

Loading…
Cancel
Save