问题:
I'm going migrate to Redux. 我要迁移到Redux。
My application consists of a lot of parts (pages, components) so I want to create many reducers. 我的应用程序包含很多部分(页面,组件),因此我想创建许多化简器。 Redux examples show that I should use combineReducers()
to generate one reducer. Redux示例显示,我应该使用combineReducers()
来生成一个reducer。
Also as I understand Redux application should have one store and it is created once the application starts. 另外,据我了解,Redux应用程序应具有一个存储,并且在应用程序启动后即会创建。 When the store is being created I should pass my combined reducer. 创建商店时,我应该通过合并的减速器。 This makes sense if the application is not too big. 如果应用程序不是太大,这是有道理的。
But what if I build more than one JavaScript bundle? 但是,如果我构建多个JavaScript捆绑包怎么办? For example, each page of application has own bundle. 例如,应用程序的每个页面都有自己的捆绑软件。 I think in this case the one combined reducer is not good. 我认为在这种情况下,一个减速器组合不好。 I looked through the sources of Redux and I have found replaceReducer()
function. 我浏览了Redux的源代码,发现了replaceReducer()
函数。 It seems to be what I want. 这似乎是我想要的。
I could create combined reducer for each part my application and use replaceReducer()
when I move between parts of application. 我可以为应用程序的每个部分创建组合的reducer,并在应用程序的各个部分之间移动时使用replaceReducer()
。
Is this a good approach? 这是一个好方法吗?
解决方案:
参考一: https://en.stackoom.com/question/2EKUC参考二: https://stackoom.com/question/2EKUC