试图绕过RxJS和redux观察我的头
我有这个:
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个可观察对象,所以我尝试了这个:
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
?
mergeMap
应该返回一个可观察的
mergeMap((data) => {
const newData = data.somethingelse
return of(fetchUserFulfilled(newData), anotherOne(newData))
}),