【问题标题】:Combining combined reducers组合组合减速机
【发布时间】:2018-01-01 03:56:23
【问题描述】:
export reducers = combineReducers ({
   app: ...,
   user: ...,
   display:...,
})

// 在配置文件中

const rootReducer = combineReducers ({
   form: formReducer,
   apollo: apolloReducer,
   reducers
})

这导致一个看起来像这样的状态树,

{
  form: {...},
  apollo: {...},
  reducers: {
    app: {...},
    user: {...},
    display: {...}
  }
}

我想要这个……

{
  form: {...},
  apollo: {...},
  app: {...},
  user: {...},
  display: {...}
}

我尝试...减速器,但没有奏效。在此先感谢

【问题讨论】:

    标签: javascript ecmascript-6 redux reducers


    【解决方案1】:

    你可以拥有一个包含所有减速器的对象,

    export reducers = {
       app: ...,
       user: ...,
       display:...,
    }
    

    然后你就可以了

    const rootReducer = combineReducers ({
       form: formReducer,
       apollo: apolloReducer,
       ...reducers
    })
    

    【讨论】:

    • 我希望这种对象方法可行。无论如何,我认为 combineReducers 能够解决这个问题。
    • combineReducers 返回的只是一个函数,一个普通的 reducer。您不能在其上使用扩展运算符。您可以做的是“减少”“减速器”,也就是有一个同时运行 reducersrootReducer 的减速器。示例:github.com/acdlite/reduce-reducers
    猜你喜欢
    • 2020-07-07
    • 2017-02-26
    • 2016-06-18
    • 1970-01-01
    • 1970-01-01
    • 2016-04-16
    • 2016-02-11
    • 1970-01-01
    • 2019-12-09
    相关资源
    最近更新 更多