我有以下动作列表,我想合并它们,以便返回动作列表并逐个执行。
我尝试过
map(drones => {
const actions = [];
drones.forEach((drone) => actions.push(new featureActions.OpenUsedDroneUpdateChannelRequest({ droneId: drone.id, projectId : environment.projectId })));
actions.push(new featureActions.GetUsedDronesSuccess({drones}));
return forkJoin(actions);
}),
我也尝试过
map(drones => {
const actions = [];
drones.forEach((drone) => actions.push(new featureActions.OpenUsedDroneUpdateChannelRequest({ droneId: drone.id, projectId : environment.projectId })));
actions.push(new featureActions.GetUsedDronesSuccess({drones}));
return merge(actions);
}),
展位不起作用
错误错误:效果“ UsedDronesEffect.getUsedDrones $”分派了一个 无效的操作:{“ _isScalar”:false}
core.js:15724 ERROR TypeError: Actions must have a type property at
如何合并它们?
答案 0 :(得分:0)
您可以尝试以下示例,也可以尝试使用mergeMap()
组合新操作
@Effect() drones = this.dronesEffect.pipe(
...,
switchMap((res: drones[]) => drones.map(x => new featureActions.OpenUsedDroneUpdateChannelRequest({ droneId: drone.id, projectId : environment.projectId })))
)
);
查看此Article
答案 1 :(得分:0)
您应该能够使用以下操作符mergeMap
,switchMap and
concatMap`中的一个返回操作数组。它也必须返回一个动作数组,为什么不逐个分发动作?