RxJS function that emit last value from one observable then other emit true

Viewed 603

Hellow, I'm trying to create function of observable (OBS) and subject(SUB) that stores last item from OBS, while SUB has F value, and emit it (and only it) when SUN becomes T

   OBS ---a----b----c----d----e----f----g----h-----
   SUB ------F----------T------------F-------T-----
   OUT -----------------c--------------------h-----

I tried to solve this with

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;
        })

but it doesn't work

2 Answers
Related