您在 Redux Observable 中预期流的位置提供了“undefined”
You provided `undefined` where a stream was expected in Redux Observable
尝试着手研究 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 个 observable,所以我尝试了这个:
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
应该 return 一个可观察的
mergeMap((data) => {
const newData = data.somethingelse
return of(fetchUserFulfilled(newData), anotherOne(newData))
}),
尝试着手研究 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 个 observable,所以我尝试了这个:
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
应该 return 一个可观察的
mergeMap((data) => {
const newData = data.somethingelse
return of(fetchUserFulfilled(newData), anotherOne(newData))
}),