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~
--
You received this message because you are subscribed to the Google Groups
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
To view this discussion on the web visit
https://groups.google.com/d/msgid/angular/f2f28209-c614-4e04-9f27-82aaf1d10deb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.