reducer.js 776 B

12345678910111213141516171819202122232425262728
  1. import * as constants from './constants';
  2. import {fromJS} from 'immutable';
  3. const defaultState = fromJS({
  4. category: [],
  5. userInfo: {},
  6. confing: {}
  7. });
  8. //immutable对象的set方法,会结合之前的immutable对象的值和设置的值,返回一个全新的对象
  9. export default (state = defaultState, action) => {
  10. switch (action.type) {
  11. case constants.GET_CATEGORY:
  12. return state.merge({
  13. category: action.data
  14. });
  15. case constants.GET_USER:
  16. return state.merge({
  17. userInfo: action.data
  18. });
  19. case constants.GET_CONFING:
  20. return state.merge({
  21. confing: action.data
  22. });
  23. default:
  24. return state;
  25. }
  26. }