【发布时间】:2016-12-22 21:11:20
【问题描述】:
假设我想要以下状态结构:
{
deep: { ... },
foo: 0,
bar: 0,
str: ''
}
deep 可能很复杂,所以我想为它提取一个专用的减速器
const deepReducer = (state = {}, action) => { ... }
对于其余部分(foo、bar 和 str),只需为它们使用另一个 reducer,因为它们非常简单
const initialState = { foo: 0, bar: 0, str: '' } // May also need to add deep here
const defaultReducer = (state = initialState, action) => { ... }
但是这个结构好像不行,如果使用 combineReducers 会分组其他reducer,那么结构会变成:
{
deep: { ... },
others: {
foo: 0,
bar: 0,
str: '',
}
}
但我不想将他们归为一类,因为他们的关系并不那么牢固。
有可能在 2 个 reducer 中实现吗?或者唯一的解决方案是为每个状态(foo、bar 和 str)创建一个专用的 reducer?
【问题讨论】:
标签: redux