2017-08-10 8 views
4

HBS、F値が の間に、観察可能な(OBS)とサブジェクト(SUB)の関数を作成しようとしています。 SUNは、TRxJS関数は、ある観測値から最後の値を放出し、その後は他の放出値を返します。

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

になったときに、それ(とのみ)を放出私は

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

でこれを解決しようとしたが、だから、あなたが何かのリクをしたいように思えるそれは

+0

'SUB'が2つの' T'を連続して出力する場合、結果として得られるobse rvableは 'SUB'が' F'のときに受け取った最後の値を生成しますか? –

+0

@SergeyKaravaev、それ以外の場合はdistinctUntilChangedで修正することができます – llCorvinuSll

答えて

2

を動作しません。 E:

SUB 
    // Only emit changes in the status 
    .distinctUntilChanged() 
    // Only forward true values down stream 
    .filter(t => t === T) 
    // Only emit the latest from OBS when you get a T from SUB 
    // Remap it so only cmd is forwarded 
    .withLatestFrom(OBS, (_, cmd) => cmd) 
+0

thx、良いスタートポイント – llCorvinuSll

2

私は自分の解決策を見つけた:

OBS 
    .buffer(SUB) 
    .withLatestFrom(SUB) 
    .map(([buffer, t]) => { 
     if(!buffer || !buffer.length) { 
      return null; 
     } 

     if(t === T) { 
      return buffer[buffer.length - 1]; 
     } 

     return null; 
    }) 
    .filter((e) => !!e); 

このバリアントは、次の行動

---a----b----c----d----e----f----g----h----- 
------F----------T------------F-------T----- 
-----------------c--------------------h----- 

があり、FとTとの間に窓が

空の場合は出力を生成しません。
---a--------------d----e----f----g----h----- 
------F----------T------------F-------T----- 
--------------------------------------h----- 
関連する問題