index.js 984 Bytes
Newer Older
1
import { connect } from 'react-redux';
张烨's avatar
张烨 committed
2
import { isImmutable } from 'immutable';
dengxiaofeng's avatar
dengxiaofeng committed
3 4 5 6 7
import * as actionCreators from './actions';
import * as constants from './constants';
import reducer from './reducer';
import * as selectors from './selectors';

8
const mapState = store => {
张烨's avatar
张烨 committed
9
  const storeObj = isImmutable(store) ? store.toJS() : store;
10 11 12
  return {
    global: storeObj.global,
    auth: storeObj.global.auth,
13
    userMode: storeObj.global.userMode,
张烨's avatar
张烨 committed
14
    loginName: storeObj.global.loginName,
15 16 17 18
  };
};
const mapDispatch = dispatch => ({
  setAuth: auth => dispatch(actionCreators.setAuth(auth)),
张烨's avatar
张烨 committed
19 20 21 22
  logout: () => {
    localStorage.setItem('token', '');
    dispatch(actionCreators.setAuth([]));
  },
23
  setUserMode: userMode => dispatch(actionCreators.setUserMode(userMode)),
张烨's avatar
张烨 committed
24
  setLoginName: loginName => dispatch(actionCreators.setLoginName(loginName)),
25
});
26

27 28 29 30 31
const appConnector = connect(
  mapState,
  mapDispatch,
);
export { actionCreators, constants, reducer, selectors, appConnector };