2

forkJoin()是否可以访问 RxJs 设备中以前的管道变量combineLatest(),在我的情况下,由于价值积累,没有嵌套管道?

switchMap()或者在以下情况下嵌套管道甚至可以吗?

// this.incrementNavigation$ emits always 1
// this.decrementNavigation$ emits always -1

this.searchSuggestions$.pipe(
  // Can't use combineLatest() due to accumulation happening in scan()
  switchMap(search => {
    return merge(this.incrementNavigation$, this.decrementNavigation$).pipe( // Nesting begins...
      startWith(0),
      scan((acc: number, cur: number) => {
        if (acc+cur < 0) return search.length-1 // Need access to search variable
        if (acc+cur > search.length-1) return 0
        return acc+cur
      }),
    )
  })
).subscribe(pos => {
  this.searchNavigationPosition = pos
})
4

0 回答 0