Is it possible to access previous pipe variables in RxJs appliances where forkJoin()
or combineLatest()
cannot be used, in my case due to value accumulation, without nesting pipes?
Or is a nested pipe with switchMap()
in the following scenario even fine?
// 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
})