在用户单击表单上的登录按钮后,我希望分派一个操作,该操作将在请求完成时触发表单上的微调工具。我已经尝试了这个问题的解决方案,但是我得到了一个错误的redux-observable dispatch actions
以下是当用户单击登录按钮时所调度的操作:
dispatch(startLoginEpic({ login: loginData, from }));这是我的史诗:
const LoginEpic = (action$, state$) =>
action$.pipe(
ofType(types.START_LOGIN_EPIC),
// map(() =>
// loginLoadBegin()),
switchMap((action) =>
from(Api.login(action.loginData))
.pipe(
map(({ data: { loginQuery: { id } } }) =>
setSession({ sessionId: id })),
catchError((error) =>
{
if (invalidSessionHelper(error))
{
return of(logOut());
}
return of({
type: 'LOGIN_EPIC_ERROR',
payload: {
error: error.message,
},
});
}),
)),
);编辑:借助@mpx2m:
const LoginEpic = (action$, state$) =>
action$.pipe(
ofType(types.START_LOGIN_EPIC),
switchMap((action) =>
concat(
of(loginLoadBegin()),
from(Api.login(action.loginData))
.pipe(
flatMap(({ data: { loginQuerdy: { id } } }) =>
concat(
of(setSession({ sessionId: id })),
of(loginLoadError()),
)),
catchError((error) =>
{
if (invalidSessionHelper(error))
{
return of(logOut());
}
return of({
type: 'LOGIN_EPIC_ERROR',
payload: {
error: error.message,
},
});
}),
),
)),
);发布于 2019-06-09 03:20:25
我的想法是:
const LoginEpic = (action$, state$) =>
action$.pipe(
ofType(types.START_LOGIN_EPIC),
switchMap((action) => concat(
of(actions.setLoading({ loading: true }),
from(Api.login(action.loginData)).pipe(
mergeMap(RESPONSE => iif(
() => RESPONSE.success === true,
of(actions.loginSuccess({ DO_SOMETHINS })),
of(actions.loginFail({ DO_SOMETHINS }))
))
)
)
))
)https://stackoverflow.com/questions/56509064
复制相似问题