Skip to content

Instantly share code, notes, and snippets.

@tmtk75
Created May 21, 2019 00:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmtk75/2499f4d084bcc173efab24498ece0477 to your computer and use it in GitHub Desktop.
Save tmtk75/2499f4d084bcc173efab24498ece0477 to your computer and use it in GitHub Desktop.
RxJS switchMap sample
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