Seamless Immutable Object的文档有set
来更新对象中键的值,但在Immutable Array文档中,没有set
来更新元素的元素阵列。
设置无缝Immutable Array
的值的首选方法是什么?
答案 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)
}
})
}