我试图在以下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
。
答案 0 :(得分:0)
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))
),
)
),
)