Last active
March 28, 2019 12:41
-
-
Save AriPal/9f4148603fa060312fdb4978deda6ab0 to your computer and use it in GitHub Desktop.
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
import { from } from 'rxjs'; | |
import { map, publishReplay, refCount } from 'rxjs/operators'; | |
// Create observable that holds two values | |
const observable$ = from(['first', 'last']).pipe( | |
publishReplay(1), | |
refCount() | |
) | |
// First time subscribing, we get both values | |
observable$.subscribe(data => console.log(data)); | |
// Second time subscribing, we get the latest value | |
observable$.subscribe(data => console.log(data)); | |
observable$.subscribe(data => console.log(data)); | |
observable$.subscribe(data => console.log(data)); | |
// OUTPUT | |
// first | |
// last | |
// last | |
// last | |
// last |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment