设置无缝不可变数组值的首选方法是什么?
What is the preferred method for setting the value of a Seamless Immutable Array?
Seamless Immutable Object has set
的文档用于更新对象中键的值,但在不可变数组文档中,没有 set
用于更新数组元素。
设置无缝 Immutable Array
值的首选方法是什么?
所以我深入研究了代码——你瞧! — 有 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)
}
})
}
Seamless Immutable Object has set
的文档用于更新对象中键的值,但在不可变数组文档中,没有 set
用于更新数组元素。
设置无缝 Immutable Array
值的首选方法是什么?
所以我深入研究了代码——你瞧! — 有 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)
}
})
}