我有一部史诗
type GetRailwaysEpic = Epic<GetRailwaysActions, AppState>;
const getRailwaysEpic: GetRailwaysEpic = (action$, state$) =>
action$.pipe(
filter(isActionOf(getRailways.request)),
switchMap(a =>
getRailways(state$.value.mileages.filters.date)
.then(getRailways.success)
.catch(getRailways.failure)
)
);
当我在任何地方调用 actions.getRailways.request() 时,它按预期工作(首先请求操作,接下来是失败的成功)
我有另一个史诗
const initEpic: Epic<FiltersActions, AppState> = (action$, state$) =>
action$.pipe(
filter(isActionOf(init)),
switchMap(({ payload: { date, depotId, locTypeId, railwayId } }) =>
of(selectDate(date)).pipe(
concat(
forkEpic(getRailwaysEpic, state$, getRailways.request())
)
)
)
);
我的 ForkEpic 功能:
function forkEpic<T extends Action, S>(
epicFactory: Epic<T, S>,
state$: StateObservable<S>,
...actions: T[]
) {
const actions$ = ActionsObservable.of(...actions);
return epicFactory(actions$, state$, null);
}
我想要什么:'init' 动作 -> 'selectDate' 动作 -> 'getRailways.request' 动作 -> 'getRailways.success' | “getRailways.failure”操作
我所看到的:'init' 动作 -> 'selectDate' 动作 -> 'getRailways.success' | “getRailways.failure”操作
'getRailways.request' 动作在某处丢失。我做错了什么?
PS getRailways - 是一个返回 Promise PPS 的函数我在这里找到了类似的问题How to chain async actions and waiting for the result without store.dispatch 但这不是我真正想要的。