I think you misunderstood how Subjects works. Subjects are hot watchers. They do not hold on to values, so if they get onNext without subscribers, that value will be lost to the world.
What you're looking for is either a BehaviorSubject or a ReplaySubject , both of which preserve past values, which are retransmitted to new subscribers. In the first case, you always build it with an initial value
in the last you set the number of values that will be played for each subscription
var subject = new Rx.ReplaySubject(1);
Rewriting your example, it could be:
var A= new Rx.BehaviorSubject(0); var B= new Rx.Subject();
In another note, understanding, of course, that this is not new to you at all, in most cases you do not need to use Subject directly, since this usually means that you are trying to argue Rx with the security of your well-known paradigms, you should ask yourself where your data? How is it created? If you ask these questions enough, following the chain of events returning to the source, 9 out of 10 times you will find that there may be an Observable wrapper for it.
source share