The docs for Seamless Immutable Object has set
to update the value of a key in an object, but in the Immutable Array docs, there is no set
for updating an element of an array.
What is the preferred method for setting the value of a Seamless Immutable Array
?
So I dug into the code — lo and behold! — there are undocumented Array methods:
My Redux reducer using the arraySet on the currentAnswer
array:
export const updateIncompleteAnswer = (state, { assignment_id, questionIndex, questionAnswer }) => {
const currentAnswer = state.incompleteAnswers[assignment_id]
return state.merge({
incompleteAnswers: {
[assignment_id]: currentAnswer.set(questionIndex, questionAnswer)
}
})
}