index.js 1.01 KB
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
  logout: () => {
    localStorage.setItem('token', '');
Maofei94's avatar
Maofei94 committed
21
    localStorage.setItem('panda-publish', '');
张烨's avatar
张烨 committed
22 23
    dispatch(actionCreators.setAuth([]));
  },
24
  setUserMode: userMode => dispatch(actionCreators.setUserMode(userMode)),
张烨's avatar
张烨 committed
25
  setLoginName: loginName => dispatch(actionCreators.setLoginName(loginName)),
26
});
27

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