Skip to content

Weird behavior of shareReplay with withLatestFrom #6605

Answered by voliva
begrs asked this question in Q&A
Discussion options

You must be logged in to vote

It has to do with the order of subscription.

withLatestFrom is meant to work with any observable, not only BehaviorSubjects and/or shareReplay()-ed observables. So the way it works is that it subscribes to the observables you give it as parameter, and then it will just append the latest value emited from them when a new value comes from source$.

On the first case, you subscribe to calculated$ before you subscribe to combined$. What happens here initially is calculated$ will subscribe to input1$ and input2$, and then you have secondSub subscribed to calculated$. The list of subscriptions is as follows:

// List of subscribers
input1$: [calculated$]
calculated$: [secondSub]

Then you subscri…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@begrs
Comment options

@gneu77
Comment options

Answer selected by begrs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants