Javascript 组合减速器
//在配置文件中Javascript 组合减速器,javascript,ecmascript-6,redux,reducers,Javascript,Ecmascript 6,Redux,Reducers,//在配置文件中 export reducers = combineReducers ({ app: ..., user: ..., display:..., }) 这会导致一个状态树,看起来像这样 const rootReducer = combineReducers ({ form: formReducer, apollo: apolloReducer, reducers }) 我想要这个 { form: {...}, apollo: {...
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: {...}
}
然后你就可以
export reducers = {
app: ...,
user: ...,
display:...,
}
我希望这种对象方法会奏效。无论如何,我认为CombinedReducer能够解决这个问题。
CombinedReducer
返回的只是一个函数,一个普通的减速机。不能在其上使用扩展运算符。您可以做的是“减少”这些“减缩器”,即有一个同时运行减缩器
和根减缩器
的减缩器。例子:
const rootReducer = combineReducers ({
form: formReducer,
apollo: apolloReducer,
...reducers
})