【发布时间】:2020-03-18 17:15:04
【问题描述】:
我有两个相同效果的实现,并且都有效。我很难理解两者之间的区别,哪个更“正确”。
请在下面找到它们:
选项 1. IDE 无法确定最后一个 map 中 instance 的类型。
pollingStarted$ = createEffect(() =>
this.actions$.pipe(
ofType(pollingStarted),
mergeMap(action => action.instances),
map(instance => performRequest({ instance }))
)
);
选项 2。所有类型都有效且有意义。这对我来说更正确,但我想弄清楚并理解其中的差异。
pollingStarted$ = createEffect(() =>
this.actions$.pipe(
ofType(pollingStarted),
mergeMap(({ instances }) =>
instances.map(instance => performRequest({ instance }))
)
)
);
【问题讨论】:
-
好问题。我希望我以前做过,它会为我省去很多麻烦!
标签: angular typescript rxjs ngrx mergemap