I'm encountering an error while trying to write an effect for an action. The error message is: "Effect "n.loadInfo$" dispatched an invalid action: null Error"
Here's my current effect implementation:
@Effect()
loadInfo$ =
this.actions.ofType(fromHeaderActions.EInfoActions.OPEN_INFO).pipe(
withLatestFrom(
this.store.select(fromSelectors.GetINFOPayload)),
switchMap(([action, infoPayLoad]) => {
let cAction: fromHeaderActions.OpenINFOWIdget =
<fromHeaderActions.OpenINFOWIdget>action;
return this.infoService.loadINFO(infoPayLoad).pipe(
// Dispatch success action
map(response => new
fromHeaderActions.OpenINFOWIdgetSuccess(response)),
catchError(error => {
return of(new
fromHeaderActions.OpenINFOWIdgetFail(error.message))
})
)
})
);
This is how I've defined my action:
export class OpenINFOWIdget extends BaseGetDetailsAction implements Action {
readonly type = EInfoActions.OPEN_INFO;
constructor() {
super();
}
}
// Additional actions:
export class OpenINFOWIdgetSuccess extends BaseGetDetailsAction
implements Action {
readonly type = EInfoHeaderActions.OPEN_INFO_SUCCESS;
constructor(public payload: INFO) {
super();
}
}
export class OpenINFOWIdget extends BaseGetDetailsAction implements Action {
readonly type = EInfoActions.OPEN_INFO_FAIL;
constructor(public payload: string) {
super();
}
}
And in the service:
public INFOPayloadsource = new BehaviorSubject<INFO>(initINFO);
infoPayload$ = this.INFOPayloadsource.asObservable();
private SelectedInfoSource = new Subject<INFO>();
selectedInfo$ = this.SelectedInfoSource.asObservable();
loadINFO(payload: INFO): Observable<INFO> {
if (payload != null) {
this.IsInfoEnableSource.next(true);
this.InfoPayloadsource.next(payload);
}
return this.selectedInfo$;
}
Here's the selector used in the effect:
export const GetINFOPayload = createSelector(getInfoState,
(state:
InfoDetailsState) => {
if (state) {
if (state.infoDetails != null &&
state.infoDetails.INFODetail !=
null &&
state.infoDetails.INFODetail.Active != null) {
let payload: INFO = { ...initINFO };
payload = state.infoDetails.INFODetail.Active;
return payload;
}
}
return null;
});
After creating the reducer:
case
fromInfoDetailsHeaderActions.EInfoHeaderActions.OPEN_INFO: {
return {
...state,
IsScreenOverlay: true,
IsEditable: false
}
};
case fromInfoDetailsHeaderActions.EInfoHeaderActions.OPEN_INFO_SUCCESS: {
return {
...state,
IsScreenOverlay: false,
IsEditable: true
}
};
Your assistance would be greatly appreciated. Thank you!