2017-11-11 21 views
2

これは実際には自分には注意しますが、他の人にとっては有益な場合があります。RxJSパイプの仕組み(lettable演算子)

だから、ここ2つのコードの断片とギッターの私の質問です:

これら二つ?:

@Effect() 
    loadRegistrationsFailed$: Observable<Action> = this.actions$ 
     .ofType(registrations.LOAD_FAIL) 
     .pipe(
      map(
       action => 
        new ShowErrorDialogAction({ 
         correlationId: new Guid(), 
         title: "Server is unreachable", 
         message: 
          "Can't load user registrations. Can't connect to the server" 
        }) 
      ) 
     ); 
``` 
and 
``` 
    @Effect() 
    loadRegistrationsFailed$: Observable<Action> = this.actions$ 
     .ofType(registrations.LOAD_FAIL) 
     .pipe(action => 
      of(
       new ShowErrorDialogAction({ 
        correlationId: new Guid(), 
        title: "Server is unreachable", 
        message: 
         "Can't load user registrations. Can't connect to the server" 
       }) 
      ) 
     ); 

答えて

1

との差が、ブラントB.のおかげで、ここでの答えはです何:

パイプ機能の仕組みに関連しています。パイプは渡された関数の配列を減らします。以前の値では、内部的にマップに渡した関数を格納するマップ関数を実行します。 2番目の例では、immediatlyのaction =>を実行し、それをパイプの結果として返します。したがって、全体に観察の結果は、値を生成するエフェクトライブラリーが加入します(アクション)であり、直ちに


同じ質問にドーロスからの回答:

の違いそれらの2つのサンプルは、最初のものが値をマッピングします。ここで、2つ目のサンプルは、全体のもので置き換えられ、ソースによって放出されたものは無視します。

秒1は

@Effect() 
loadRegistrationsFailed$: Observable<Action> = this.actions$ 
    .ofType(registrations.LOAD_FAIL) 
    .pipe(ob => ob.mergeMap(action => 
     of(
      new ShowErrorDialogAction({ 
       correlationId: new Guid(), 
       title: "Server is unreachable", 
       message: 
        "Can't load user registrations. Can't connect to the server" 
      }) 
     )) 
    ); 

アクションを使用していけないので、あなたもmergeMapToまたはmepToを使用することができますでしょう書き込むための正しい方法:

@Effect() 
loadRegistrationsFailed$: Observable<Action> = this.actions$ 
    .ofType(registrations.LOAD_FAIL) 
    .pipe(ob => ob.mergeMapTo(of(
      new ShowErrorDialogAction({ 
       correlationId: new Guid(), 
       title: "Server is unreachable", 
       message: 
        "Can't load user registrations. Can't connect to the server" 
      }) 
     )) 
    ); 

賃貸可能オペレーターが追加唯一のものであることです.pipe(ob => ob.map())の代わりに.pipe(map())を書くことができます

関連する問題