#Dispatch action conditionaly based on previous action response

26 messages ยท Page 1 of 1 (latest)

jagged pumice
velvet kestrel
#

you are missing the default return

#

and the return for the else

#

you need to validate all use cases

#

but I agree, the error is not simple to understand

jagged pumice
#

I even tried to add empty action for default case, but seems not good enough ๐Ÿ˜‰

velvet kestrel
#

you are missing the else case

jagged pumice
#

I have covered that case also by adding
else {
return PlanningActions.emptyAction();
}
but still the same issue

#

public onUpdateOptimizationResult$ = createEffect(() =>
this.actions$.pipe(
ofType(PlanningActions.updateOptimizationResult),
switchMap(({ message }) => {
if (message.status && message.startDate && message.expectedEndDate) {
switch (message.status) {
case RopOptimizationStatusEnum.OPTIMIZATION_CANCELLED:
return PlanningActions.cancelOptimization();
case RopOptimizationStatusEnum.OPTIMIZATION_FINISHED:
return PlanningActions.finishedOptimization();
default:
return PlanningActions.emptyAction();
}
} else {
return PlanningActions.emptyAction();
}
})
)
);

velvet kestrel
#

can you show me your action definition?

jagged pumice
velvet kestrel
#

and emptyAction?

jagged pumice
#

const emptyAction = createAction('[Planning Page] Empty Action');

velvet kestrel
#

and the error message is still the same?

jagged pumice
#

Yeap, on hover i see the same error message

#

Just to show on what type of action I am listening, it supposed to return message object

velvet kestrel
#

ok got it

#

you are using switchmap

#

but you are not doing any async operation inside your effect

#

switchmap let your flat map obs<obs<any>>

#

so here a simple map is enough

jagged pumice
#

so true ๐Ÿ˜‰

#

omg, how easy it is to forget basic stuff about effects ๐Ÿ˜‰

velvet kestrel
#

that more about rxjs but yes sometimes you are so focus on something. you forgot to look elsewhere

#

you should mark your thread as valid with the โœ… on your first message so that others will see it

jagged pumice
#

Yeap, I just resolved it ๐Ÿ˜‰ thanks man, I am happy to be part of this awesome community