Created
January 24, 2019 04:22
-
-
Save webhacking/c5533c425a8f43db66b9ed37bda5caaf to your computer and use it in GitHub Desktop.
Replay Subject Example
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 {ReplaySubject} from 'rxjs/internal/ReplaySubject'; | |
const subject = new ReplaySubject(2 /* buffer size */); | |
subject.next('a'); | |
subject.next('b'); | |
subject.next('c'); | |
const subscription = subject.subscribe((x: string) => { | |
console.log(`Next: ${x}`); | |
}, (error: Error) => { | |
console.log(`Error: ${error}`); | |
}, () => { | |
console.log('Completed'); | |
}); | |
// => Next: b | |
// => Next: c | |
subject.next('d'); | |
// => Next: d |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment