Redux 在父减速器的默认块中调用子减速器

Redux 在父减速器的默认块中调用子减速器,redux,react-redux,Redux,React Redux,在其默认块中,让一个减速机调用子减速机可以吗 function aReducer(state = {}, action) { switch(action.type) { case XYZ: ... // know what to do default: // don't know this action, let's delegate to the children return { sub1: subReducer1(st

在其默认块中,让一个减速机调用子减速机可以吗

function aReducer(state = {}, action) {
  switch(action.type) {
    case XYZ:
      ... // know what to do
    default:
      // don't know this action, let's delegate to the children
      return {
        sub1: subReducer1(state.sub1, action),
        sub2: subReducer2(state.sub2, action)
        }
  }
}

您可以将所有的简化程序放在一个公共文件夹中,在该文件夹中,您可以将单独的简化程序组合成一个单独的简化程序,如下面的代码所示

import { combineReducers } from 'redux'
import Reducer1 from './Reducer1.js'
import Reducer2 from './Reducer2.js'
export default combineReducers( { Reducer1, Reducer2,... } )
并使用以下代码将其用作单个减速器

import reducers from '../../reducers'(reducer's root folder name/path)
let store = createStore( reducers );

是的,这是绝对合法和合理的

您可能还想通读本文,进一步了解如何组织reducer逻辑