我正在下面的史诗中发出ajax请求,但是在mergeMap开始调用之前,我想触发RESET_IMAGE操作,但是,下面的代码无法实现。有可能还是有人可以看到我在做什么错了?
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
})
)
)
)
);
答案 0 :(得分:1)
您可以使用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
})
)
)
)
)
);