我是rxjs和redux-observables的新手
我有两个史诗:
export const navigation = ($action, {getState}) =>
$action.ofType(actions.locationChange)
.do(console.log)
和
export const navigation = ($action, {getState}) =>
$action.ofType(actions.locationChange)
.switchMap(({payload: {pathname}}) =>
$action.ofType(action.fetchDataSuccess)
.take(1)
App Init触发取回数据的操作, 是否可以保持导航史诗直到获取数据完成?因此,如果收到导航动作并且获取数据没有完成,我们将等待获取数据完成(dispatch action.fetchDataSuccess)并继续导航史诗流程?
我尝试了以下代码,但是fetchDataSuccess等待新的fetchDataSuccess之后的每个请求
{{1}}
答案 0 :(得分:1)
尝试使用withLatestFrom:
export const navigation = ($action, {getState}) =>
$action.ofType(actions.locationChange)
.withLatestFrom(appInit)
.filter(([locationChangeEvent, appInitEvent]) => {
return /* check that app inited successfully */
})
.map(([locationChangeEvent]) => locationChangeEvent)
.do(console.log)