【发布时间】:2019-06-01 01:50:07
【问题描述】:
我想了解当我直接通过管道传递给 action$ 并尝试使用 forkJoin 运算符时会发生什么
const action1 = { type: "ACTION_1" };
const action2 = { type: "ACTION_2" };
在 switchMap forkJoin 中工作正常。
export const testForkJoinSwitchMap: Epic<Action> = action$ =>
action$.pipe(
ofType(action1),
switchMap(() =>
forkJoin(
from(fetch("https://api.github.com/users")).pipe(
map((res: any) => {
return res;
})
)
)
),
map((data: any) => {
// do something with data
return action2;
})
);
如果我把它从 switchMap 中取出来:
export const testForkJoin: Epic<Action> = action$ =>
action$.pipe(
ofType(action1),
forkJoin(from(fetch("https://api.github.com/users"))).pipe(
map((response: any) => {
return action2;
})
)
);
我输入错误:
Argument of type 'Observable<{ type: string; }>' is not assignable to parameter of type 'OperatorFunction<{}, Action<any>>'.
我想知道为什么它不能编译?以及类型不匹配的原因,是什么让没有forkJoin的史诗在这种情况下无效?
编辑:我知道 forkJoin 对于单个 observable 没有意义,但我放 1 以使示例更小
【问题讨论】:
标签: rxjs redux-observable