是否可以在没有 forkJoin 或 combineLatest 的情况下访问管道变量?

是否可以访问 RxJs 组件中以前的管道变量,其中 forkJoin()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
})
haihaome1 回答:是否可以在没有 forkJoin 或 combineLatest 的情况下访问管道变量?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/1086036.html

大家都在问