如何将参数传递给 createSelector 的结果函数(重新选择)

How to pass parameters to the result Function of a createSelector (reselect)

我的 redux store 有两个独立的切片 A 和 B,

我需要一个记忆的选择器,它 returns 从 B 派生的东西,只有当 A 改变时。

例如

const getSliceA = (state) => state.A

export const getSliceB = createSelector(
 getSliceA,
 (a) => {  return MyDerive(state.B) }
) 

我的问题是如何将状态或 state.B 发送到 resultFunc。

const compareBySliceA = (prevSate: RootState, newState: RootState) => {
    // This is just an example you can compare inner of Slice A
    if (newState.SliceA === prevState.SliceB) {
        return true
    }   
    return false;
};

const getDerivedSliceB (state: RootState): List<any> => 
    state.SliceB.filter(ElementB => ElementB.visible) 


const createComparatorSelector = createSelectorCreator(
  defaultMemoize,
  compareBySliceA,
);


 export const myDeepSelector = createComparatorSelector(
  (state: RootState) => state,
  (state: RootState): List<any> => getDerivedSliceB(state),
);

compareBySliceA和getDerivedSliceB都需要共同的parent,即上面例子中的State是SliceA和SliceB的parnet。