1

如何构建一个 Redux 选择器来收集全局和本地派生数据?

我有一些看起来像这样的数据:

{
  palette: [1,0,1,1],
  children: [
    {
      RootData: [...],
     },
     //more children...
  ]
}

我需要添加一些计算得出的派生属性。DerivedRootComputedFromPaletteAndDerivedRoot

{
  palette: [1,0,1,1],
  children: [
    {
      RootData: [...],
      // Local data for this child derived from the RootData
      DerivedRoot: [], 

      // Additional data derived from global `palette` and local `RootData`
      ComputedFromPaletteAndDerivedRoot: []
    },
    //more children...
  ]
}

我查看了重新选择,但不确定它是否是在这种情况下使用的正确工具。

单个孩子的RootData值可能会改变,我不希望选择器应用于完整的孩子集合,因为这会在单个孩子发生变化时重新记忆所有孩子。此外,任何时间palette更改子选择器都可以重新计算新值ComputedFromPaletteAndDerivedRoot

4

0 回答 0