3
I have the following scenario: I’m manipulating the object namespaced questions
, within it exists list
and news
, want to create a mutation
that adds a key value pair in questions
within those two arrays
.
I want a generic function that knows which of the two arrays is, and changes that specific Question.
const SET_TYPING_COMMENT = (state, question) => {
state.list = [
...state.list.map(_question => {
if (_question.id == question.id) {
_question = { ..._question, typing: true };
}
return _question;
})
];
state.news = [
...state.news.map(_question => {
if (_question.id == question.id) {
_question = { ..._question, typing: true };
}
return _question;
})
];
};