I am a beginner when it comes to working with Observables. Here's the Effect that I am using:
My goal is to dispatch the PositionUpdateAction or PositionFailedAction before the SunriseSunsetAction is dispatched.
Currently, what happens is that the result of getCurrentPosition() is passed into the last map in the result variable, and then the SunriseSunsetAction is dispatched. Neither the PositionUpdateAction nor PositionFailedAction are being dispatched.
I believe that I need to incorporate concat in some way. I've tried different approaches but haven't been successful.
I would really appreciate any guidance or assistance on this matter.
@Effect()
position$: Observable<Action> = this.actions$.pipe(
ofType(ActionType.GetPosition),
mergeMap(() =>
fromPromise(this.geo.getCurrentPosition()).pipe(
map(value => new UiActions.PositionUpdateAction(value)),
catchError((err) => {
return of(new UiActions.PositionFailedAction(err));
})
).map(result =>
new UiActions.SunriseSunsetAction(this.sun.calculateSunriseSunsetWindows(result.payload.lat, result.payload.long))
)
)
);