我试图在以下redux-observable史诗中“取消”( takeUntil
)AJAX调用,同时保留catchError
效果。
const someEpic = action$ =>
action$.pipe(
ofType(REQUEST_MAPPED_ESTABLISHMENTS),
map( action => ( // transform data to url )),
mergeMap( url =>
ajax({ url }).pipe(
mergeMap( establishments => {
const { error, data } = establishments.body
if (error) throw 'some error';
return of(actions.receiveMappedEstablishments(data))
}),
catchError(error =>
(of(actions.requestMappedEstablishmentsFailure(error)))
),
)
),
)
上面的摘录如何重组为包含takeUntil
,例如以下内容?
takeUntil(action$.ofType(UI_HAS_CHANGED_SO_NEW_DATA_NOW_REQUIRED))
到目前为止,我仅成功完全取消了一些someEpic
,例如,将takeUntil
插入到action$.pipe
。
const someEpic = action$ =>
action$.pipe(
ofType(REQUEST_MAPPED_ESTABLISHMENTS),
map( action => ( // transform data to url )),
mergeMap( url =>
ajax({ url }).pipe(
mergeMap( establishments => {
const { error, data } = establishments.body
if (error) throw 'some error';
return of(actions.receiveMappedEstablishments(data))
}),
catchError(error =>
(of(actions.requestMappedEstablishmentsFailure(error))),
takeUntil(action$.ofType(UI_HAS_CHANGED_SO_NEW_DATA_NOW_REQUIRED))
),
)
),
)