说,我有这个史诗:
export const getUserEpic = action$ => action$
.ofType(t.GET_USER)
.mergeMap(action => Observable
.from(query.findUser(action.uid))
.map(user => ({ type: t.GET_USER_SUCCESS, user }))
.takeUntil(action$.ofType(t.GET_USER_CANCELLED))
然后,我多次派遣t.GET_USER
的某个地方:
dispatch({ type: t.GET_USER, uid: 'uid1' })
dispatch({ type: t.GET_USER, uid: 'uid2' })
dispatch({ type: t.GET_USER, uid: 'uid3' })
如何取消其中一个?例如:
dispatch({ type: t.GET_USER_CANCELLED, uid: 'uid2' })
AFAIK,.takeUntil(action$.ofType(t.GET_USER_CANCELLED))
将取消所有t.GET_USER
次操作。我只需要取消一个。
答案 0 :(得分:3)
您可以使用.filter()
谓词仅取消订阅您正在寻找的uid
的mergeMap:
export const getUserEpic = action$ => action$
.ofType(t.GET_USER)
.mergeMap(action => Observable
.from(query.findUser(action.uid))
.map(user => ({ type: t.GET_USER_SUCCESS, user }))
.takeUntil(
action$
.ofType(t.GET_USER_CANCELLED)
.filter(act => act.uid === action.uid)
)