Rxjs 如果在Redux可观察史诗中
我有一个epic,它捕获每个获取状态的分派(只是来自状态的项,比如state.process:{status:fail,success,inWork},而不是请求状态,比如200500等等)。 当status==success(通过从state获取status)时,我需要发送另一个操作,如SET\u status\u successRxjs 如果在Redux可观察史诗中,rxjs,observable,redux-observable,Rxjs,Observable,Redux Observable,我有一个epic,它捕获每个获取状态的分派(只是来自状态的项,比如state.process:{status:fail,success,inWork},而不是请求状态,比如200500等等)。 当status==success(通过从state获取status)时,我需要发送另一个操作,如SET\u status\u success const getStatus = (action, state) => action.pipe( ofType(GET_STATUS
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.
}
})
);
现在我收到错误消息:
未捕获类型错误:您提供了“函数(源){return
lift(new-MapToOperator(value));}'中,其中需要流。
您可以提供一个可观察的、承诺的、数组的或可观察的。
在subscribeTo(subscribeTo.js:41)
我该怎么办?我尝试只返回setStatusSuccess操作,但它也不起作用。您需要从传递到
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;
}
}),
);
和从导入。您需要从传递到
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;
}
}),
);
并且是从中国进口的