The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Starting a Stream with SwitchMap

Starting a Stream with SwitchMap

5:48
As developers, we tend to carry over ideas from past experience and try to reapply them to something new. This lesson teaches you about why you should usually favor `switchMap` over `subscribe` and why thinking about `subscribe` as an event handler can lead to problems.
Watch this lesson now
Avatar
egghead.io

As developers, we tend to carry over ideas from past experience and try to reapply them to something new. This lesson teaches you about why you should usually favor switchMap over subscribe and why thinking about subscribe as an event handler can lead to problems.

Avatar
Adam

How are you able to use switchMapLatest()?

In reply to egghead.io
Avatar
Dany

Look at this link https://github.com/ReactiveX/RxJS/blob/master/MIGRATION.md, it looks like they renamed switchMapLatest to switchMap in the version 5.

In reply to Adam
Avatar
nader dabit

Does switchMap have any documentation? I ask because I could not find any.

In reply to egghead.io
Avatar
Christopher Da Silva

This has been named flatMapLatest* in the newest stable version of RxJs(4.x.x). Take a look at flatMap and it's variants. http://reactivex.io/documentation/operators/flatmap.html. In the video(using v5 beta) You will notice them using switchMap and switchMapTo which is , as of now, the new name for these variants. Please see these migration docs mentioned above :https://github.com/ReactiveX/RxJS/blob/master/MIGRATION.md

In reply to nader dabit
Avatar
Stephen James

You can see it happen, but I didn't see it explicitly stated, when the outer observable emits and event (click), the previous inner observable (the timer) is completed and a new one is started, that is why you don't get the behavior of multiple timers running that you did with subscribe in subscribe

In reply to egghead.io
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?