结合使用选择器的嵌套结果

问题描述:

我正在使用重新选择从商店中派生我的数据。我保留一份DivisionsTeams的清单,每个部门都有它的清单。我还保留了现役部门的记录,并将他们保存在一个阵列中activeIds结合使用选择器的嵌套结果

基本上我有这样的树结构:

const divisions = { 
    activeIds: [], // this contains the selected division IDs 
    list: { 
     1: { 
     name: 'Division 1', 
     teams: [1,2,3] 
     } 
     2: { 
     name: 'Division 2', 
     teams: [4,5,6] 
     } 
     // and so on... 
    } 
} 

const teams = { 
    1: { name: 'Team 1' } 
    // and so on... 
} 

我有一个getActiveDivisions选择器遍历的activeIds阵列,并与司数据水合它,其结果是:

// if activeIds contain [1,3] 

const activeDivisions = { 
    1: { 
    name: 'Division 1', 
    teams: [1,2,3] 
    } 
    3: { 
    name: 'Division 3', 
    teams: [7,8,9] 
    } 
} 

现在我想要创建一个getActiveDivisionsWithTeams选择器,它基本上获得与activeDivisions树相同的结构,但使用水合团队,例如:

const activeDivisionsWithTeams = { 
    1: { 
    name: 'Division 1', 
    teams: { 
     1: { name: 'Team 1' }, 
     2: { name: 'Team 2' }, 
     3: { name: 'Team 3' } 
    } 
    } 
    // and so on... 
} 

或者我应该为水师队保留一份不同的名单?

// Notice there is no `name` on division entry 
const activeDivisionsWithTeams = { 
    1: { 
    teams: { 
     1: { name: 'Team 1' }, 
     2: { name: 'Team 2' }, 
     3: { name: 'Team 3' } 
    } 
    } 
    // and so on... 
} 

或者什么是最好的方法来处理这种情况?

我不认为这是充分补充水分的好习惯。

如果您要为所有团队显示某些内容,请将每个ID传递给子组件,然后可以使用选择器来获取所需的数据。

或者如果您正在做一些需要不同部分数据的计算,那么在选择器内部执行此操作,而不是返回完全水合的数据。