Closed TylerYang closed 7 years ago
It isn't so much a problem with any of the operators as it is with the source. data1$
is a an of
operator which is cold by default but by using share you are turning it into a hot Observable. The first subscription causes the single value from data1$
to emit so that by the time that you get to the second subscription it has already emitted. combineLatest
will only emit once it has data from both sources so it will never emit. You can see this work if you change of
to timer(1000)
for instance, because data1$
will then emit well after both subscriptions have been made.
We deal with a lot of hot observables at my work and see this regularly, like Paul described. When you're using multiple subscriptions and if you can't easily ensure that all subscriptions are in place before the needed values are emitted you can use shareReplay(1)
instead which will cache the last value to come through and replay it to any late subscribers like the combineLatest above.
hi @paulpdaniels @whiteinge Thx so much for the detailed explanation!
Now I got the idea of hot
and code
observable! And shareReplay
could satisfy my need perfectly!
Hi guys, it looks like
combineLatest
doesn't work as expected on ashared
observable collection. Consider the code below,In this case combineLastest won't output any result. I'm not sure if I used it correctly, but only if It could work only if I commented out
data1$.subscribe...
.I created this jsfiddle link for testing. http://jsfiddle.net/zba86st0/238/
Any comments would be appreciated. Thx : )