1

我有以下选择器

const getLinkFeatureState = createFeatureSelector<ILinkReducer>('link');

export const getLinkIsLinkDtoPricesDeliveryTimesSome = (index: number) => createSelector(
  getLinkFeatureState,
  state => state.linkDto.prices[index].deliveryTimes.some(d => d.iso == state.???)
)

现在我想使用我的另一个减速器的状态

export interface ISelectedLanguageReducer {
  language: ILanguage;
  isLanguageSuccess: boolean;
}
const selectedLanguageInitial: ISelectedLanguageReducer = {
  language: {
    country: '',
    value: '',
    selected: false
  },
  isLanguageSuccess: false
}

使用以下选择器

const getSelectedLanguageFeatureState = createFeatureSelector<ISelectedLanguageReducer>('selectedLanguage');
export const getSelectedLanguageLanguage = createSelector(
  getSelectedLanguageFeatureState,
  state => state.language
);

有什么方法可以在“链接”选择器中获取所选语言或在选择器中使用选择器?

4

1 回答 1

1

您可以通过直接在createSelector函数中添加另一个选择器来实现这一点,如下所示:

export const getLinkIsLinkDtoPricesDeliveryTimesSome = (index: number) =>
    createSelector(getLinkFeatureState, getSelectedLanguageLanguage, (state, selectedLang) =>
        // >>> you can use the selectedLang here
        state.linkDto.prices[index].deliveryTimes.some((d) => d.iso == state.???)
    );

确保在使用之前在模块中初始化另一个状态。

createSelector您可以在Using selectors for multiple pieces of state中检查此重载。

于 2021-09-01T10:06:24.627 回答