問題:
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