我有一个 flatMap ,目的是发出两个动作:
export default function searchForPartner(action$, store) {
return action$.ofType(statusActions.SEARCH_FOR_PARTNER)
.filter(() => store.getState().user.signedIn)
.delay(2000)
.flatMap(() => [
carouselActions.slideTo(config.CAROUSEL_SLIDES.CONFIRM_CHAT),
statusActions.foundPerson(),
])
.takeUntil(action$.ofType(carouselActions.TAP_CANCEL))
};
但是,takeUntil
是在错误的位置。它在TAP_CANCEL
发射时取消了整个史诗。相反,我只希望它取消内部动作的发射flatMap
。我该怎么做?
=== 更新 ===
我愚弄了它,这似乎有效?但我不喜欢有 2 个计时器:
export default function searchForPartner(action$, store) {
return action$.ofType(statusActions.SEARCH_FOR_PARTNER)
.filter(() => store.getState().user.signedIn)
.mergeMap(() =>
Observable.merge(
Observable.timer(2000)
.map(() => carouselActions.slideTo(config.CAROUSEL_SLIDES.CONFIRM_CHAT)),
Observable.timer(2000)
.map(() => statusActions.foundPerson())
)
.takeUntil(action$.ofType(carouselActions.TAP_CANCEL))
)
};