使用 redux 在商店中更新嵌套数据数组的最佳/正确方法是什么?
我的商店是这样的:
{
items:{
1: {
id: 1,
key: "value",
links: [
{
id: 10001
data: "some more stuff"
},
...
]
},
...
}
}
我有一对更新完整items
对象的异步操作,但我还有另一对要更新特定links
数组的操作。
我的减速器目前看起来像这样,但我不确定这是否是正确的方法:
switch (action.type) {
case RESOURCE_TYPE_LINK_ADD_SUCCESS:
// TODO: check whether the following is acceptable or should we create a new one?
state.items[action.resourceTypeId].isSourceOf.push(action.resourceTypeLink);
return Object.assign({}, state, {
items: state.items,
});
}