【发布时间】:2015-11-13 02:57:52
【问题描述】:
我正在尝试使用“cmets”对象实现一个reducer,该对象包含由某个ID 索引的cmets 数组。我想合并而不是替换“cmets”对象中的属性。
现在我有这个:
commentsReducer {
comments: {}
1: Array[9]
2: Array[5]
isFetchingComments: true
lastUpdated: null
}
我的 Reducer 函数:
function commentsReducer(state = {
isFetchingComments: false,
lastUpdated: null,
comments : {}
},action){
switch(action.type){
case RECEIVE_COMMENTS:
var new_cm = {[action.pid]: action.comments};
return Object.assign({}, state, new_cm);
}
}
我正在尝试做的事情:
commentsReducer {
comments {
1: Array[9],
2: Array[5]
}
isFetchingComments: true
lastUpdated: null
}
【问题讨论】:
标签: javascript reactjs redux