Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

求教:modules里面怎么获取大的state啊 #74

Open
volcanG opened this issue Jun 6, 2017 · 3 comments
Open

求教:modules里面怎么获取大的state啊 #74

volcanG opened this issue Jun 6, 2017 · 3 comments

Comments

@volcanG
Copy link

volcanG commented Jun 6, 2017

代码结构是这样

--src\routes\Subscribe\index.js
const container = require('./containers/SubscribeContainer').default const reducer = require('./modules/Subscribe').default /* Add the reducer to the store on key 'counter' */ injectReducer(store, { key: 'subscribe', reducer })

--\src\routes\Subscribe\modules\Subscribe.js
[SUBSCRIBE_CHANGE_VIEW]: (state) => { console.info('-----------debug------------------') console.info(state) return { ...state, showStyle: state.showStyle === 'table' ? 'view' : 'table' } }

--\src\store\reducers.js
`import { combineReducers } from 'redux'
import locationReducer from './location'
import navBarReducer from '../components/NavBar/modules/NavBar'
import loginReducer from '../components/Login/modules/Login'

export const makeRootReducer = (asyncReducers) => {
return combineReducers({
navbar:navBarReducer,
location: locationReducer,
DATA:loginReducer,
...asyncReducers
})
}

export const injectReducer = (store, { key, reducer }) => {
store.asyncReducers[key] = reducer
store.replaceReducer(makeRootReducer(store.asyncReducers))
}

export default makeRootReducer`

--\src\components\Login\modules\Login.js
const ACTION_HANDLERS = { [LOGIN_FETCH_SUCCESS]: (state, action) => { return ({ ...action.payload }) } }

业务逻辑是这样,登录成功将获取的数据放入大的state(modules\Login.js),然后modules\Subscribe.js需要处理这个大的state.
modules里面怎么获取大的state啊,modules\Subscribe.js reducer 处理只能获取到当前的key('subscribe')下得state状态,怎么获取大的state 的属性值啊,我想获取DATA。

@volcanG
Copy link
Author

volcanG commented Jun 26, 2017

20天了啊,没人回啊!!/(ㄒoㄒ)/~~

@bodyno
Copy link
Owner

bodyno commented Jun 26, 2017

这个很简单的
设成redux放到全局就可以了

@volcanG
Copy link
Author

volcanG commented Jun 27, 2017

不太懂啊,现在各自modules获取是自身key的state值啊,拿不到大的store啊,最近刚学实在想不明白。
------routes
injectReducer(store, { key: 'subscribe', reducer })
-------modules
[SUBSCRIBE_CHANGE_VIEW]: (state) => {
console.info('-----------debug------------------')
console.info(state) //此处获取的是store中key值为‘subscribe’的state,怎么获取整个store??
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants