避免重复redux存储中的嵌套对象

避免重复redux存储中的嵌套对象,redux,reducers,redux-orm,Redux,Reducers,Redux Orm,我正在尝试,从我收集的信息来看,redux orm在存储中创建了一个对象,它的键是通过Model.name为每个注册的模型指定的值 好的,为了创建我的“实体”减缩器,我使用了组合减缩器,为我的所有实体传递减缩器,如下所示: import { combineReducers } from 'redux'; import City from './cityReducer'; import Poi from './pointOfInterestReducer'; const entitiesRedu

我正在尝试,从我收集的信息来看,redux orm在存储中创建了一个对象,它的键是通过
Model.name
为每个注册的模型指定的值

好的,为了创建我的“实体”减缩器,我使用了组合减缩器,为我的所有实体传递减缩器,如下所示:

import { combineReducers } from 'redux';
import City from './cityReducer';
import Poi from './pointOfInterestReducer';

const entitiesReducer = combineReducers({
  City,
  Poi
});

export default entitiesReducer;

最后,这就是我如何创建我的
rootReducer
,也使用
combinereducer

问题是,我认为,通过使用
组合减速机
我复制了我存储中的密钥,如下图所示:

你知道我该如何避免这种情况,并且让我的所有模型都是“实体”的直接后代吗

类似于
entities>City
而不是
entities>City

编辑:cityReducer.js
有两种方法可以使用Redux ORM定义其“表”结构,并编写reducer逻辑来使用这些表。我在我的博客文章中给出了这两种方法的例子。(请注意,这些文章介绍了Redux ORM 0.8的使用,0.9版有一些API更改。我在中列出了这些更改。)

第一种方法是编写附加到模型类的reducer逻辑,并使用Redux ORM
ORM
实例生成一个reducer,该reducer创建“表”并为您管理它们。Per:

另一种方法是编写自己的函数来创建初始状态,也可能编写其他函数来处理更新:

import {orm} from "./models";

const initialState = orm.getEmptyState();

export default function entitiesReducer(state = initialState, action) {
    // handle other actions here if desired
    return state;
}

换句话说,不要自己定义每个模型类型的单独“表”。让Redux ORM在自己的reducer中自动定义这些,或者使用它为实体reducer生成初始状态。

plz共享城市ReducerOne!请看编辑。
import {createReducer} from "redux-orm";
import {orm} from "./models";

const rootReducer = combineReducers({
    entities: createReducer(orm)
});
import {orm} from "./models";

const initialState = orm.getEmptyState();

export default function entitiesReducer(state = initialState, action) {
    // handle other actions here if desired
    return state;
}