switchmap Questions
3
Solved
Let's say, I have a stream of actions. Each action is assigned some id. Like this:
const actions$ = of({ id: 1 }, { id: 2 }, { id: 1 });
Now, for each action, I want to perform some logic in swi...
Halvah asked 6/7, 2019 at 20:5
1
Solved
Let's look at this piece of code:
let isNull = true;
const a$ = new Subject<void>();
const b$ = a$.pipe(
switchMap(() => {
if (!isNull)
return of(true).pipe(
tap(() => console.log('...
3
Solved
I have a use case whenever a new request is triggered, any http requests that are already in flight should be cancelled / ignored.
For eg:
A request (say #2) comes in while the request #1 t...
Competitive asked 28/2, 2018 at 18:17
3
Solved
I have a simple setup to show a loading spinner when the async pipe is null:
<div *ngIf="(searchResults$ | async) as searchResults; else loading">
</div>
<ng-template #loading>
...
Drinking asked 17/2, 2019 at 21:46
2
Solved
I have some trouble to understand this. When I use the switchMap operator with an Observable it emits all the values as expected:
Observable.from([1, 2, 3, 4, 5])
.do(console.log)
.switchMap(i =...
Bricabrac asked 17/2, 2018 at 16:32
2
Solved
In my project, I sometimes want to update the available options in a list when the user changes the selected value in another list. To do this, I've used valueChanges with the pipe operator and swi...
Shirleyshirlie asked 1/4, 2022 at 14:27
4
I have a situation like the following:
myObservable1.pipe(
switchMap((result1: MyObservable1) => {
if (condition) {
return myObservable2;
} else {
return of(null);
}
})
).subscribe(myObse...
Few asked 21/5, 2018 at 16:24
2
Solved
I'm using Angular (9) powered Bootstrap (6.1.0) TypeAhead and defining its search function like so:
search = (text$: Observable<string>) => {
return text$.pipe(
debounceTime(200),
disti...
1
Solved
I sent the below code snippet for code review. This effect needs to dispatch a success action after a request call, or an error action if the service method throws an error, so pretty standard.
@E...
Englebert asked 14/11, 2019 at 10:33
1
Solved
return this.auth.user.pipe(
switchMap((user: IUser) => {
return of(true);
})
);
My initial code was a bit more complex with some cases depending on the user data, but for testing purposes ...
Displease asked 13/9, 2019 at 14:57
1
Solved
I want to cancel the previous http request if i made the new http request to server but it is not working as expected to me.
i want to cancel the request if some value got changed in the function ...
Bullet asked 9/7, 2019 at 18:6
2
Solved
as per the definition of the switchMap
On each emission the previous inner observable (the result of the
function you supplied) is cancelled and the new observable is
subscribed. You can remem...
Eureetloir asked 5/4, 2019 at 8:9
1
Solved
So I am new to RXJS. What I am trying to do is setup a session expiration timer, and when a user receives a modal prompt that their session is about to expire, if they click Continue, the timer is ...
1
© 2022 - 2025 — McMap. All rights reserved.