Created
May 21, 2019 00:30
-
-
Save tmtk75/2499f4d084bcc173efab24498ece0477 to your computer and use it in GitHub Desktop.
RxJS switchMap sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { of, interval, never } from "rxjs"; | |
import { map, switchMap } from "rxjs/operators"; | |
const a = of(1, 2, 3, 4); | |
const b = of(1, 2, 3, 4).pipe(map(e => e * 10)); | |
const c = of(1, 2, 3, 4).pipe(map(e => e * 100)); | |
const main = interval(1000).pipe( | |
switchMap(i => { | |
switch (i % 3) { | |
case 0: | |
return a; | |
case 1: | |
return b; | |
case 2: | |
return c; | |
} | |
return never(); | |
}) | |
); | |
main.subscribe(console.log); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment