I have my Angular 5 code working without ngrx effect. After adding effect and send HTTP request, I can not trigger reducer to be invoked by an action. My effect is this. This console log is getting hit with the correct http response.
@Injectable()
export class PropertyEffects {
@Effect({dispatch: false})
propertyFetch$: Observable<Action> = this.actions$//.pipe(
.ofType(PropertyActions.FETCH_ALL_PROPERTIES)
.switchMap(action =>
this.httpClient.get('https://yxalbf1t6l.execute-api.us-east-1.amazonaws.com/dev/todos').pipe(
// If successful, dispatch success action with result
map(data => {
console.log(`Success ${JSON.stringify(data)}, 0, 2)`);
return new PropertyActions.OpenAllProperties(data)
})
)
);
My reducer for the OpenAllProperties action below was getting called correctly before using effect. With effect, its console log never gets hit.
case PropertyListActions.OPEN_ALL_PROPERTIES:
console.log("in reducer, action.payload: " + JSON.stringify(action.payload,null,2))
const openAllProperties = !state.openAllProperties;
return {
...state,
openAllProperties: openAllProperties
}
Please help. thank you!
You are passing a parameter to stop the dispatching the event. That will not trigger the reducer function because it does not dispatch anything.
If you want to verify it use redux dev tools
In there you will see all dispatch event in the application.