我有一部史诗,可以捕获每次获取状态的信息(只是状态中的项,例如state.process:{status:失败,成功,inWork},而不是请求状态,如200、500等)。当状态==成功时(通过从状态获取状态),我需要调度其他操作,例如SET_STATUS_SUCCESS
const getStatus = (action, state) =>
action.pipe(
ofType(GET_STATUS),
withLatestFrom(state),
mergeMap(([action, state]) => {
const { status } = state.api.process; //here is what i need, there is no problem with status.
if (status === "success") {
return mapTo(SET_STATUS_SUCCESS) //got nothing and error.
}
})
);
现在我收到错误:
未捕获的TypeError:您提供了'function(source){return source.lift(new MapToOperator(value)); }'预计会出现流。您可以提供一个Observable,Promise,Array或Iterable。在subscriptionTo(subscribeTo.js:41)
我该怎么办?我试过只是返回setStatusSuccess操作,但是它也不起作用。
您需要从传递给的函数中返回一个observable mergeMap
。尝试这个:
const getStatus = (action, state) =>
action.pipe(
ofType(GET_STATUS),
withLatestFrom(state),
mergeMap(([action, state]) => {
const { status } = state.api.process;
if (status === 'success') {
return of({ type: SET_STATUS_SUCCESS });
} else {
return EMPTY;
}
}),
);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句