redux文档使用lodash合并功能提供了“简单合并”方法: https://github.com/reduxjs/redux/blob/e7097be3edcc2ba76cbb6d3aea77e63be2d7e80c/docs/recipes/structuring-reducers/UpdatingNormalizedData.md#standard-approaches
“它也无法处理删除项目的操作。”
要删除项目,不是使用lodash“ mergeWith”并传递仅使数组随实体传递的自定义程序的解决方案。像这样:
function entities (state = initialState, action) {
function customizer(fromState, fromEntities) {
if (isArray(fromState)) {
return fromEntities;
}
}
if(action.entities) {
return mergeWith({}, state, action.entities, customizer);
}
switch (action.type) {
default:
return state;
}
}
到目前为止,对于我个人的用例来说,它似乎运行良好(在我所有的数组中,我都引用了其他实体)。但是肯定有一些情况我不在这里考虑。使用_.mergeWith而不是_.merge是否看到任何问题?