【发布时间】:2018-01-03 19:08:03
【问题描述】:
我写这段代码是为了创建 Redux store:
import {combineReducers} from 'redux-immutable'
const MyAppReducers = combineReducers({
Node1: Node1Reducer,
Node2: Node2Reducer,
Node3: Node3Reducer,
Node4: Node4Reducer
})
let store = createStore(
MyAppReducers,
composeEnhancers(
applyMiddleware(
thunkMiddleware,
ApiMiddleware,
loggerMiddleware
)
)
)
这个配置的结果是一个普通的对象,里面有Immutable.Map()s:
{
Node1: Immutable.Map(),
Node2: Immutable.Map(),
Node3: Immutable.Map(),
Node4: Immutable.Map()
}
相反,我希望所有状态树都是Immutable.Map()。
所以我尝试直接将Immutable.Map() 对象传递给combineReducers():
const MyAppReducers = combineReducers(Immutable.Map({
Node1: Node1Reducer,
Node2: Node2Reducer,
Node3: Node3Reducer,
Node4: Node4Reducer
}))
但这会在控制台中引发错误:
未捕获的类型错误:reducer 不是函数
在 combineReducers.js:39
在 Array.forEach ()
在 combineReducers.js:36
在 Map.withMutations (immutable.js:1353)
在 combineReducers.js:35
在 computeNextEntry (:2:27469)
在重新计算状态 (:2:27769)
在:2:31382
分派时 (createStore.js:165)
在 createStore (createStore.js:240)
redux-immutable 的文档指出我应该将initialState 作为createStore 函数的第二个参数传递,但我的第二个参数目前是composeEnhancers 函数,我需要配置中间件和其他东西。
如何使整个状态树成为Immutable.Map() 对象?
【问题讨论】:
标签: javascript redux immutable.js redux-immutable