Hello, I'm attempting to design a function that involves an observable (OBS) and a subject (SUB). The goal is to capture the last item from OBS while SUB is in state F, and then emit this particular value only when SUB transitions to state T.
OBS ---a----b----c----d----e----f----g----h-----
SUB ------F----------T------------F-------T-----
OUT -----------------c--------------------h-----
I have attempted to tackle this challenge with the following code:
OBS.window(SUB)
.withLatestFrom(SUB)
.switchMap(([window, status]) => {
if(status === F) {
return window.combineLatest(SUB, (cmd, status) => {
if(status === T) {
return null;
};
return cmd;
}).last((e) => {
return !!e;
})
}
return Observable.empty<Command>();
}).filter((cmd) => {
return !!cmd;
})
Unfortunately, the solution does not seem to be working as expected.