NGRX效果仅从combineLatest中得到最终省略

问题描述 投票:0回答:1

我从我的服务返回一个

combineLatest
,这是对我的后端的请求集合。我通过
switchMap
听我的效果。这些请求按预期工作,然后当它们全部完成时,我会得到我的响应。

然而,我需要的是在排放发生时聆听它们。我也尝试过使用

zip
但没有运气。我得到的唯一发射是最后一个。

代码是这样的:

// Effect
createEffect(() => {
   return this.action$.pipe(
      ofType(someAction),
      switchMap(action => { 
        return this.service.doSomething().pipe(
           tap(results => ...nothing happens until the end),
           map(results => ...do stuff)
        )
      })
    )
});

// Service

public doSomething() {
   const requests = someData.map(data => this.http.get(...))

   return combineLatest(requests).pipe(
      tap(results => // nothing happens here until the end
   )
}

有什么想法吗?看起来 NGRX 在幕后正在丢弃其他排放

ngrx ngrx-effects
1个回答
0
投票

NGRX 不会丢弃排放。 从问题来看,您似乎正在寻找

merge
运算符而不是
combineLatest
merge
将发出返回的每个值。

© www.soinside.com 2019 - 2024. All rights reserved.