2017-04-24 21 views
1

私はredux-observableを使って叙事詩を書いています。複数のフィルタ(oftype)を使って叙事詩を書こうとしています。以下は私のサンプルコードです複数のフィルタを使ってredux-observable epicを作成する

export const landingEpic = action$ => { 
    console.log('inside landing epic'); 
    return action$.ofType('APPLY_SHOPPING_LISTS').map(() => (
     { 
      type: 'APPLYING_SHOPPING_LISTS', 
     }) 
    ); 

    return action$.ofType('APPLIED_SHOPPING_LIST'){ 
     //here I want to return something else 
    } 
} 

しかし、私は1つの叙事詩で2つの返信方法を使用することはできません。

答えて

0

あなたがcombineEpicsを使いたいように聞こえる:

import { combineEpics } from "redux-observable"; 

const landingEpic1 = // put epic1 definition here 

const landingEpic2 = // put epic2 definition here 

export default combineEpics(
    landingEpic1, 
    landingEpic2, 
    // ... 
); 
+0

理想的には、これをすべて1つの叙事詩に収めるのが理にかなっているので、私はこれを1つにします。 –

3

あなたはそれを返し、その後Observable.merge()でそれらを組み合わせることをお勧めします - 私はまた、非常に二つの別々の叙事詩にそれらを分離する提案が。テストするのが簡単になりますが、それはあなたの呼び出しです。

export const landingEpic = action$ => { 
    return Observable.merge(
    action$.ofType('APPLY_SHOPPING_LISTS') 
     .map(() => ({ 
     type: 'APPLYING_SHOPPING_LISTS', 
     }), 

    action$.ofType('APPLIED_SHOPPING_LIST') 
     .map(() => ({ 
     type: 'SOMETHING_ELSE', 
     }), 
); 
} 
関連する問題