设置Seamless Immutable Array的值的首选方法是什么?

时间:2017-11-17 20:26:37

标签: javascript arrays seamless-immutable

Seamless Immutable Object的文档有set来更新对象中键的值,但在Immutable Array文档中,没有set来更新元素的元素阵列。

设置无缝Immutable Array的值的首选方法是什么?

1 个答案:

答案 0 :(得分:0)

所以我挖掘了代码 - 瞧瞧! - 有undocumented Array methods

我的Redux reducer使用currentAnswer数组上的arraySet

export const updateIncompleteAnswer = (state, { assignment_id, questionIndex, questionAnswer }) => {
  const currentAnswer = state.incompleteAnswers[assignment_id]
  return state.merge({
    incompleteAnswers: {
      [assignment_id]: currentAnswer.set(questionIndex, questionAnswer)
    }
  })
}