我有一个异步 actionCreator 来处理我的应用程序的身份验证流程:
function createAuthenticationResponse(err, grant) {
return {
type: AUTHENTICATION_RESPONSE,
payload: err || grant,
error: Boolean(err)
}
}
function authenticate() {
// return a thunk.
return dispatch => {
// Notify the system that we are authenticating.
dispatch({ type: AUTHENTICATE });
// Trigger the auth flow.
myAuthModule.authorize((err, grant) => {
// Trigger a state-change on the outcome.
dispatch(createAuthenticationResponse(err, grant));
// Q: How do I handle this side-effect?
if (!err) {
dispatch(extractUserInfo(grant));
}
});
};
}
如果用户成功通过身份验证,我的 actionCreator 包含从授权中提取用户信息的业务逻辑;这个逻辑应该存在于我的动作创建者中吗?如果没有,我应该把它放在哪里,在我的减速器内?
在其他架构中,我会绑定一个命令来触发AUTHENTICATION_RESPONSE
;但这感觉不像是中间件工作?