Rxjs 在Redux中,ofType后面必须紧跟一个map操作符吗?
我在下面的epic中提出了一个ajax请求,但就在mergeMap开始调用之前,我想启动RESET_IMAGE操作,但是,下面的代码没有实现这一点。有没有可能或者有人能看出我做错了什么Rxjs 在Redux中,ofType后面必须紧跟一个map操作符吗?,rxjs,redux-observable,Rxjs,Redux Observable,我在下面的epic中提出了一个ajax请求,但就在mergeMap开始调用之前,我想启动RESET_IMAGE操作,但是,下面的代码没有实现这一点。有没有可能或者有人能看出我做错了什么 const imageUploadEpic = (action$, state$) => action$.pipe( ofType('UPLOAD_IMAGE'), mapTo('RESET_IMAGE'), mergeMap(action => from(
const imageUploadEpic = (action$, state$) =>
action$.pipe(
ofType('UPLOAD_IMAGE'),
mapTo('RESET_IMAGE'),
mergeMap(action =>
from(
axios.post(`/uploads/url`, {
url: action.src
})
).pipe(
map(response => ({
type: 'UPLOAD_IMAGE_SUCCESS',
data: response.data
})),
catchError(error =>
of({
type: 'UPLOAD_IMAGE_ERROR',
error
})
)
)
)
);
您可以使用
concat
生成如下两个操作:
const imageUploadEpic = (action$, state$) =>
action$.pipe(
ofType('UPLOAD_IMAGE'),
mergeMap(action =>
concat(
of({ type: 'RESET_IMAGE' }),
from(
axios.post(`/uploads/url`, {
url: action.src
})
).pipe(
map(response => ({
type: 'UPLOAD_IMAGE_SUCCESS',
data: response.data
})),
catchError(error =>
of({
type: 'UPLOAD_IMAGE_ERROR',
error
})
)
)
)
)
);