-
-
Save ajcrites/779f1f2ba6d481425efcb8ab6af50a13 to your computer and use it in GitHub Desktop.
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 { Observable } from 'rxjs/Observable'; | |
import 'rxjs/add/observable/interval'; | |
import 'rxjs/add/operator/switchMap'; | |
import 'rxjs/add/operator/map'; | |
import 'rxjs/add/operator/mapTo'; | |
// This observable is subscribed to and emits observables | |
Observable.interval(1000) | |
.switchMap(() => | |
// This inner observable is 'flattened' by `.switchMap` and folded into the outer observable stream | |
Observable.interval(1000).mapTo('a') | |
.map(a => { | |
// This will be logged because it is part of the same observable stream | |
console.log(a); | |
// Nothing subscribes to this observable | |
return Observable.interval(1000).mapTo('b') | |
.map(b => { | |
console.log(b); | |
return 'called'; | |
}) | |
}) | |
// This logs out the observable returned from the inner Observable | |
).subscribe(obs => console.log(obs)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment