Answer the question
In order to leave comments, you need to log in
Rxjs switchMap, why how many subscribe so many requests?
query() {
сonsole.log('query');
}
let search$ = new BehaviorSubject('');
let x = search$
.distinctUntilChanged()
.do(() => console.log('search called!'))
.mergeMap(() => query());
x.subscribe(data => console.log('data'));
x.subscribe(data => console.log('data'));
x.subscribe(data => console.log('data'));
x.subscribe(data => console.log('data'));
query
data
query
data
query
data
query
data
search$.next('asd');
query
data
query
data
query
data
query
data
Answer the question
In order to leave comments, you need to log in
For each subscribe, the whole chain works out, such is the behavior.
Fast decision:
let x = search$
.distinctUntilChanged()
.do(() => console.log('search called!'))
.mergeMap(() => query())
.shareReplay(1);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question