试图围绕 RxJS 和 redux observable
我有这个:
export const getSomeData = (action$) =>
action$.pipe(
ofType(GET_USER_DATA),
mergeMap((action) => getData(action.id)),
map(fetchUserFulfilled),
catchError((e) =>
of({
type: 'FAILED_TO_FETCH_DATA',
e,
}),
),
)
效果很好,但是现在我想在取回数据时实际触发 2 个 observables,所以我尝试了这个:
export const getSomeData = (action$) =>
action$.pipe(
ofType(GET_USER_DATA),
mergeMap((action) => getData(action.id)),
mergeMap((data) => {
const newData = data.somethingelse
of(fetchUserFulfilled(newData), anotherOne(newData))
}),
catchError((e) =>
of({
type: 'FAILED_TO_FETCH_DATA',
e,
}),
),
)
但这失败了。那么我该如何解决这个问题,我有什么误解,我应该如何mergeMap
正确使用?