I have an observable and I'm trying to make a replay subject from. It should emit the current and all previous events that the observable emitted.
Here is what I thought would work, as per this answer:
// create an observable from dummy array and a blank replay subject
const observable$ = from([1, 2, 3])
const replay$ = new ReplaySubject()
// create a replay subject from the observable (not working as expected)
observable$.subscribe(replay$)
// log out the events
observable$.subscribe(e => console.log('observable', e) )
replay$.subscribe(e => console.log('replay', e))
Logs
observable 1
observable 2
observable 3
replay 1
replay 2
replay 3
The behavior I'm looking for is such that the replay subject emits the previous events as well, like so:
replay [1]
replay [1, 2]
replay [1, 2, 3]
How can I archieve this?