In my program, I have an intermediate stream that is connected to a source, but it can also trigger events from other sources (such as user input). In another part of my code, there is a derived stream that needs to compare new data from the intermediate with the last value of the source. This is the snippet of code that handles this scenario:
const source = new Rx.Subject;
const derived = new Rx.Subject;
derived.subscribe( () => console.log( "derived" ) );
const intermediate = new Rx.Subject;
// The reason for having the "intermediate" stream is that sometimes it triggers on its own:
source.subscribe( intermediate );
intermediate
.withLatestFrom( source )
.subscribe( derived );
source.next();
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/5.4.3/Rx.min.js"></script>
The issue here is that the "derived" message is never displayed (the first event in the source is being ignored). How can I create a stream that retrieves the last value of the source for every message from the intermediate stream, even if the source is currently propagating?