在redux-observable中,我需要等待执行API请求,直到另一个史诗完成。使用CombineLatest不起作用,在APP_INITIALIZED完成后什么也没有发生。我也尝试了用LatestFrom,但是都没有用。
const apiGetRequestEpic = (action$, store) => {
return Observable.combineLatest(
action$.ofType('APP_INITIALIZED'),
action$.ofType('API_GET_REQUEST')
.mergeMap((action) => {
let url = store.getState().apiDomain + action.payload;
return ajax(get(url))
.map(xhr => {
return {type: types.API_RESPONSE, payload: xhr.response};
})
.catch(error => {
return Observable.of({ type: 'API_ERROR', payload: error });
});
})
);
};
Run Code Online (Sandbox Code Playgroud)