2017-11-03 31 views
0
export const mySelector = createSelector(
    [selectorA, selectorB], // but I want selectorB or selectorC to be chosen here using logic 
    (foo, bar) => { 
     // ... 
    } 
); 

再選択使用してセレクタを構成selectorBまたはselectorCストア内の状態に基づいて、このセレクタ(別のセレクタによって返さすなわち値)を作成します。は条件付きIが条件付きで使用する

どうすればいいですか?

+0

は再選択を試していません。値を決定するためにロジックを使用していて、どのような問題がありますか? – guest271314

+0

@ベン私の答えからアイデアを得たら教えてください。 –

+0

ありがとうございます。 – Ben

答えて

1

ある

selectorX

、selectorB、selectorCを構成selectorCorBを行います受け入れられた答えは、それぞれ セレクタBセレクタCをそれぞれ セレクタCorBと呼びます。おそらく望ましい動作ではないでしょうか。

実際の条件付き呼び出しは、このように実装されることがあります。

export const selectorCorB = createSelector(
    selectorStateX 
    (...arguments) => arguments, 
    (x, arguments) => x ? selectorB(...arguments) : selectorC(...arguments) 
); 
1

次いでselectorXちょうどアプローチがで提案ことを指摘することselectorB又はselectorCのいずれかを決定する店舗からの変数xのセレクタ

const selectorCorB = createSelector(
    selectorB, 
    selectorC, 
    selectorStateX, 
    (b, c, x) => x? b: c 
) 

mySelector = createSelector(
    [selectorA, selectorCorB], // will be A AND B OR C depending on x 
    (foo, cOrb) => { 
     // ... 
    } 
);