在我的 React 应用程序中,我appReducer
管理全局内容,例如通知、用户信息等。
应用程序中的module之一是库存module,它有自己的减速器,即inventoryReducer
. 在 redux store 中,我组合了所有的 reducer。
当用户输入库存条目时,除了处理库存事务之外,我还想显示一个在appReducer
. 中如何更新的状态displayNotification
这是根据appReducer
从inventoryReducer
?
以下是我的应用程序减速器:
import 'babel-polyfill';
import * as types from '../actions/actionTypes';
const initialState = {
displayNotification: {}
};
export default (state = initialState, action) => {
switch (action.type) {
case types.DISPLAY_NOTIFICATION :
return Object.assign({}, state, {
displayNotification: action.value
})
default: return state
}
}
这是inventoryReducer
:
import 'babel-polyfill';
import * as types from '../actions/actionTypes';
const initialState = {
inventory: []
};
export default (state = initialState, action) => {
switch (action.type) {
case types.SET_INVENTORY :
return Object.assign({}, state, {
inventory: action.inventoryItem
})
case types.DISPLAY_NOTIFICATION :
return Object.assign({}, state, {
app.displayNotification: action.value // <-- Is this how I access `displayNotification` which is managed by the `appReducer`?
})
default: return state
}
}
我的更新清单操作需要同时调度SET_INVENTORY
和DISPLAY_NOTIFICATION
。我想知道我怎么可以更新displayNotification
从inventoryReducer
这里displayNotification
实际上是由管理appReducer
。