Hi all
I've been searching for days and I'm still struggling to come up with a solution. I have an NGRX action that sets a 'currentId' and passes off to a success action. I'm passing in the action payload (which is required in the success action) but I would also like to compare against the existing 'currentId' with means accessing the state...
Most solutions seem to suggest that
withLatestFrom()
is the obvious solution, however, using withLatestFrom whilst providing no errors during build, seems to stop the effect from running at all.
Here is what i have currently, which works for the payload:
@Effect()
setCurrentId$: Observable<Action> = this.actions$.pipe(
ofType<actions.SetCurrentId>(actions.ActionTypes.SET_CURRENTID),
map(action => {
return new actions.SetCurrentIdSuccess({ Id: action.payload.Id });
})
);
What I would like to do is get the currentId from the state to compare against, ideally passing a new parameter to the success effect (something like isNew: boolean). According to other forums, this should work:
@Effect()
setCurrentId$: Observable<Action> = this.actions$.pipe(
ofType<actions.SetCurrentId>(actions.ActionTypes.SET_CURRENTID),
withLatestFrom(this.store.select(state => state.feature.currentId)),
map(([action, currentId]) => {
return new actions.SetCurrentIdSuccess({ Id: action.payload.Id, IsNew: (currentId !== action.payload.currentId) });
})
);
However, this effect doesn't even seem to run although it generates no errors on build. This should be so simple to access state from within the effect but I am obviously missing something!
Can anyone help please? Let me know if more information is required!
Thanks
~S~