0

I had a hard time finding out from where the events are dispatched. But I have noticed that the GET_USER_SUCCESS is only fired when you edit the already fetched user from server on initial load.

effect.ts:

//Get users
this.getUsers$ = this.actions$.pipe(
    ofType(GET_USERS),
    switchMap(() =>
        this.service.getUsers()
            .pipe(
                map((users) => new GetUsersSuccess(users)),
                catchError(error => of(new GetUserFail(error)))
            )
    )
);

//Update a newly created user
this.updateUser = this.actions$.pipe(
    ofType(UPDATE_USER),
    map((action: any) => action.payload),
    switchMap(form => {
        return this.service.updateUser(user)
            .pipe(                              map((user) => new UpdateUserSuccess(user)),
                catchError(error => of(new UpdateUserFail(error)))
            );
    })
);

In my reducer.ts:

switch (action.type) {
    case CREATE_USER_SUCESS:
        return adapter.addOne(action.payload, state);

    case GET_USER_SUCCESS:
    return adapter.addAll(action.payload, state); -->Getting fired

    case UPDATE_USER_SUCCESS:
        return adapter.updateOne({
            id: action.payload.id,
            changes: action.payload
        }, state);
    default:
        return state;
}

0 Answers0