Is it possible to postpone handling an action in effect until some other action is dispatched? here the exact scenario:
1.dispatch action A1
2.effect handle A1 and request an http call
3.before http call is finished action B1 is dispatched
4.effect want to handle action B1 but it needs a part of store which is not ready until the "A1 http request" is completed
I handle it by a variable inside effect class, but I'm looking for a cleaner solution. here is my code
numberOfDelaying=0;
handleB1 = createEffect(() => {
return this.actions.pipe(
ofType(DashboardActions.B1),
withLatestFrom(this.store.pipe(select(someSelector))),
concatMap(([action, stateSlice]) => {
//need the state slice which is not ready until A1 is completed
if(!stateSlice && this.numberOfDelaying<10){ // here i check if the data is not ready dispatch B1 after 100 ms
this.numberOfDelaying++;
return of(DashboardActions.B1()).pipe(delay(100));
}
else if (stateSlice){
// do some async call
}
else {
return of(DashboardActions.Error())
}
})
);
});