迭代数组并使用 Immunity Helper 为 Redux Reducer 更改某个 属性

Iterate over array and change a certain property using Immunity Helper for a Redux Reducer

我正在尝试学习 Immunity Helper,因为我认为它会对我的 Reducers 有所帮助,但我不知道如何更改数组所有对象中的 属性。

请大家帮忙,卡了这么久

https://github.com/kolodny/immutability-helper https://facebook.github.io/react/docs/update.html

我的初始状态

outputList: [
  { propertyIWantToChange: 'some value1' },
  { propertyIWantToChange: 'some value2' },
  { propertyIWantToChange: 'some value3' }, etc
]

不工作的减速器。我觉得我的语法有点不对劲,但我不知道是哪一部分。

case types.SOME_TYPE: {

  return update(state, {
    outputList: {
      propertyIWantToChange: {$set: action.value}
    }
  });

您将不得不遍历该数组。如果该列表接受 map 那么像这样的东西应该可以工作,我猜:

case types.SOME_TYPE: {
  const lst = state.outputList.map((el) => {
    return update(el, { propertyIwantToChange: {$set: action.value}}
  });

  return update(state, { outputList: {$set: lst}})
}