I reviewed the following SO question: What are the Hot and Cold observables?
- a cold observable emits its values when it has an observer to consume them, i.e. the sequence of values received by observers is independent of time of subscription. All observers will consume the same sequence of values.
- a hot observable emits value independently of its subscriptions, i.e. the values received by observers are a function of the time of subscription.
Yet, I feel like hot vs. cold is still a source of confusion. So here are my questions:
Are all rx observables cold by default (with the exception of subjects)?
I often read that events are the typical metaphor for hot observables, but I also read that
Rx.fromEvent(input, 'click')is a cold observable(?).
Are there/what are the Rx operators which turn a cold observables into a hot observable (apart from
For instance, how does it work with Rx operator
cold$be a cold observable which has somewhere been subscribed to. Will
sth$.withLatestFrom(cold$,...)be a hot observable?
Or if I do
sth1$.withLatestFrom(cold$,...), sth2$.withLatestFrom(cold$,...)and subscribe to
sth2, will I always see the same value for both
Rx.fromEventcreates cold observables but that is not the case, as mentioned in one of the answers. However, I am still baffled by this behaviour : . Different subscriptions get different values from the same observable. Wasn't the