1

I have an effect which calls Actions on 2 different states, its current state an another.

@Effect()
    sendPointOfInterestChatMessage$ = this.actions$.pipe(
        ofType(chatActions.ChatActionTypes.SendPointOfInterestChatMessage),
        switchMap((action: chatActions.SendPointOfInterestChatMessage) => this.chatService.sendMessage(action.pointOfInterest.chatMessage.chatRoomId,
            action.pointOfInterest.chatMessage.content,
            false,
            false,
            false).pipe(
                switchMap((data: any) => {
                   ...content excluded

                    return [ 
                        new chatActions.AddChatMessage(chatMessage), 
                        new mapActions.CreatePointOfInterest(copyPointOfInterest) 
                    ];
                }),
                catchError((error: HttpErrorResponse) => {
                    const errorMessage = this.handleError('Error Sending Chat Message', error);
                    return of(new chatActions.SendChatMessageFailure('SendChatMessageError: ' + errorMessage));
                })
            ))
    );

Both the chatActions.AddChatMessage and mapActions.CreatePointOfInterest execute successfully. However, the mapActions.CreatePointOfInterest also fires actions as follows

@Effect()
  createPointOfInterest$ = this.actions$.pipe(
    ofType(mapActions.MapActionTypes.CreatePointOfInterest),
    switchMap((action: mapActions.CreatePointOfInterest) => 
    this.mapService.createPointOfInterest(action.pointOfInterest).pipe(
            switchMap((data: any) => { 
                ...excluded content

                return [new mapActions.CreatePointOfInterestSuccess(pointOfInterest), new mapActions.CreatePointOfInterestSuccess2("testing")];
            }),
            catchError((error: HttpErrorResponse) => {
                const errorMessage = this.handleError('Error Creating Point of Interest', error, false);
                return of(new mapActions.CreatePointOfInterestFailure('CreatePointOfInterestError: ' + errorMessage));
            })
        ))
);

At this point, the mapActions.CreatePointOfInterestSuccess Action is fired as I see the call in the State inspector, however, the Reducer is not ever triggered

export function reducer(state = initialState, action: MapActions): MapState {
    switch (action.type) {       
        case MapActionTypes.ResetError:
            return {
              ...state,
              error: null
            };
case MapActionTypes.CreatePointOfInterestSuccess:
            ...content excluded
            }
            return {
                ...state,
                pointsOfInterest: copyCreatePointOfInterestSuccessPointsOfInterest,
                correlatedPointsOfInterest: copyCreatePointOfInterestSuccessCorrelatedPointsOfInterest,
                error: null
            };

I am never seeing the CreatePointOfSuccess reducer code actually fired. Even with CreatePointOfInterest2 that only passes a string, never gets fired. Why is this reducer never being fired?

JoeyD
  • 693
  • 4
  • 25
  • The only suspicious code I see is the usage of `MapActionTypes`. Are you sure that the string type of the `CreatePointOfInterest` action is the same as `MapActionTypes.CreatePointOfInterestSuccess`? – mat.hudak Nov 10 '21 at 12:00
  • it is. I actually found the issue that was happening. There was a previous call that was failing and actually breaking the State, so when this action call was made the state could not respond – JoeyD Nov 10 '21 at 13:57

0 Answers0