我写了这段代码来创建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()
。
所以我试图combineReducers()
直接传递给一个Immutable.Map()
对象:
const MyAppReducers = combineReducers(Immutable.Map({
Node1: Node1Reducer,
Node2: Node2Reducer,
Node3: Node3Reducer,
Node4: Node4Reducer
}))
但这会在控制台中引发错误:
未捕获的TypeError:减速器不是函数
在CombineReducers.js:39
在Array.forEach()
在CombineReducers.js:36
在Map.withMutations(immutable.js:1353)
在CombineReducers.js:35
在computeNextEntry(:2:27469)
在recomputeStates(:2:27769)
在:2:31382
分派时(createStore.js:165)
在createStore(createStore.js:240)
redux-immutable
状态文档,我应该将initialState
_作为createStore
函数的第二个参数传递,但是我的第二个参数当前composeEnhancers
是我需要配置中间件和其他东西的函数。
如何使整个状态树成为Immutable.Map()
对象?
内置combineReducers
函数希望看到的状态是纯Javascript对象。
如果要让状态树成为Immutable.js
Map
替代,则需要使用其他功能,例如由提供的功能redux-immutable
或其他Redux /不可变互操作库。
请注意,ReduxcreateStore
函数可以调用为:
createStore(rootReducer, initialState, composedEnhancers);
createStore(rootReducer, composedEnhancers);
因此,将您的首字母Immutable.js
Map
作为第二个参数传递。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句