如何将参数传递给 createSelector (reselect) 函数的结果
2018-09-13
564
1个回答
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 都需要共同的父级,也就是上例中 State 是 SliceA 和 SliceB 的父级。
Hiran
2018-11-07