0

我正在尝试创建一个选择器,该选择器返回一个对象列表,其中包含从另一个选择器添加的额外字段。这是我尝试使用的选择器:

//Get a full list of Users with their Roles added
export const getUsersWithRoles = createSelector(
  getAllUsers,
  (userList) => userList.map(user => getUserWithRolesById(user.userId))
);


//Get User and add their Roles to the object
export const getUserWithRolesById= (userId: string) => createSelector(
  getUserById(userId),
  getRoleListByUserId(userId),
  (user, roles) => {
    const userWithMembership = {...user, roles: roles} as UserTableItem;
    return userWithMembership;
  }
);

但是,getUsersWithRoles选择器返回的是一个 MemoizedSelectors 数组,而不是一个对象数组。如何在第一个选择器中使用该getUserWithRolesById选择map器?

其他一切都与 ngrx 的实体模式一样工作,但我将列出在上面的代码中调用的一些选择器:

//Selectors


export const getUserManagerDataState = createFeatureSelector<UserManagerState>(USER_MANAGER_DATA_FEATURE_KEY);

export const getUsersState = createSelector(
  getUserManagerDataState,
  (state) => state.userState
);

export const getAllUsers = createSelector(
  getUsersState,
  UserAdapterSelectors.selectAll
);

export const getUserById = (userId: string) => createSelector(
  getUserManagerDataState,
  state => state.userState.entities[userId]
);

4

0 回答 0