RxJs: how to get values emitted before we subscribe?
Asked Answered
C

1

2

With RxJs, once we start subscribe to an observable, we will start getting values once they are emitted, but how do I get all the values emitted by an observable before I've subscribed to it?

Cabretta answered 22/12, 2016 at 11:15 Comment(1)
I had a similar question here: #45436718 solution was to use ReplaySubjectHelban
O
1

An observable is just a function that returns 0 or more values between now and the end of time. Like any other function it doesn't do anything before it's called (subscribed to).

That being said, you can transform your observable to a hot observable by calling:

// This makes the observable 'connectable'
myObservable.publish();
// And make it start emitting items
myObservable.connect();

Alternatively, if you create the observable from say an array, you could ofcourse just look at the array :)

Ott answered 22/12, 2016 at 11:20 Comment(1)
That's clearest and most concise explanation I've read. Thanks Robba!Cabretta

© 2022 - 2024 — McMap. All rights reserved.