Created
May 19, 2018 07:23
-
-
Save shairez/f1f1a89ba1c4fa36b309eb260307e104 to your computer and use it in GitHub Desktop.
Code examples for the switched-a-map blog post
This file contains 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
// A FAKE SERVER OBJECT: | |
const http = { | |
getAwesomeMessagesObservable(name): Observable<string> { | |
return of(`${name} is awesome! (msg #1)`, | |
`${name} is awesome! (msg #2)`); | |
} | |
// the "of" returns an observable | |
// this particular one will produce 2 events | |
} | |
// FOR THE VALUE "Pete", ONCE WE SUBSCRIBE, THIS SHOULD RETURN: | |
// Pete is awesome! (msg #1) | |
// Pete is awesome! (msg #2) |
This file contains 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
// Awesome Mapping | |
const namesObservable = of('Pete', 'Mike'); | |
namesObservable.pipe( | |
map(name => `${name} is awesome!`) | |
).subscribe(result => console.log(`${result}`)); | |
// CONSOLE: | |
// Pete is awesome! | |
// Mike is awesome! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment