this stackoverflow: NgRx - Order of execution of Reducers and Effects says that effects run before reducers in ngrx. However my effect:
@Effect({dispatch:false})
updateToken$ = this.actions$.pipe(
ofType<UpdateToken>(AuthActionTypes.UpdateToken),
mergeMap((action) =>
this.auth.getUsernameFromToken(action.token).pipe(map(username
=> {
action.username=username;
})
)
),
catchError(()=> EMPTY)
);
runs before my reducer:
case AuthActionTypes.UpdateToken:
console.log("update token returning new state...... action
is",action);
return {username:action.username,token:action.token};
which I can tell since the effect updates action.username, and the reducer prints it.
What's more, it doesn't even make sense to me why effects would run before reducers.It doesn't make sense because the effect is where you are meant to make requests according to the docs, and you may need to update the state based on the result of the request, which you couldn't do if the reducer ran first.
Can anyone please help me understand? (Please don't say something like "you're an idiot. you dont understand how any of this works and your question is an error." :))