@Effect({ dispatch: false })
public setJwtDataParcoursPage = this.actions$.pipe(
ofType(INIT_FORM_SUCCESS_ACTION),
map((action: InitFormSuccessAction) => action.payload),
withLatestFrom(this.store.select(this._apiHeadersSelector.getJwt) as Observable<string>),
switchMap(([payload, jwt]: [InitResponse, string]) => {
const params = { jwt, userId: payload.jwt.user.id }
return forkJoin([
of(payload),
iif(
() => payload.subscriptionManagement,
this.subscriptionService.getSubscriptionInfo(params).pipe(map(subscription => subscription.body)),
of(null)
)
])
}),
map(([payload, subscriptionData]) => {
const subscriptionStatus = this.getValue(subscriptionData?.status, payload.jwt.env.subscriptionManagement);
this._analyticsService.updateParcoursVars(payload, subscriptionStatus, "parcours", "form");
this.store.dispatch(new GetSubscriptionInfoSuccessAction(subscriptionData))
}),
catchError(_ => {
...
return of([])
})
);
I have other tasks happening in //.
When payload.subscriptionManagement
is false
, everything works as expected. The chaining is not interrupted by other // tasks.
But when payload.subscriptionManagement
is true
, the code does not immediately reach the last part:
map([payload, subscriptionData] => {...
It returns to this part later.
My question is, how can I modify this code to keep the chaining uninterrupted?
Update: I have tried the following approach:
@Effect({ dispatch: false })
public setJwtDataParcoursPage = this.actions$.pipe(
ofType(INIT_FORM_SUCCESS_ACTION),
map((action: InitFormSuccessAction) => action.payload),
withLatestFrom(this.store.select(this._apiHeadersSelector.getJwt) as Observable<string>),
switchMap(([payload, jwt]: [InitResponse, string]) => {
const params = { jwt, userId: payload.jwt.user.id }
return forkJoin([
of(payload),
iif(
() => payload.jwt.env.subscriptionManagement,
of(this.subscriptionService.getSubscriptionInfo(params)),
of(null)
)
])
}),
map(([payload, subscriptionData]) => {
subscriptionData.subscribe(subscription => {
const subscriptionStatus = this.getValue(subscription?.body.status, payload.jwt.env.subscriptionManagement);
this._analyticsService.updateParcoursVars(payload, subscriptionStatus, "parcours", "form");
this.store.dispatch(new GetSubscriptionInfoSuccessAction(subscription.body))
})
}),
Now, when payload.subscriptionManagement
is true
, it enters the
map([payload, subscriptionData] => {
section but the effect is interrupted when subscribe
.