categoryReducer.js 1.08 KB
'use strict';

import InitialState from './categoryInitialState';
import Immutable, {Map} from 'immutable';

const {
	SET_TYPE,
	GET_CATEGORY_SUCCESS,

	SET_CURRENT_CATEGORY_ID,
	SET_CURRENT_CHANNEL_ID,

	JUMP_TO_CATEGORY,
} = require('../../constants/actionTypes').default;

const initialState = new InitialState;

export default function categoryReducer(state=initialState, action) {
    switch(action.type) {

		case SET_TYPE: {
			return state.set('type', action.payload);
		}
		case GET_CATEGORY_SUCCESS:{
			let {
				boy,
				girl,
				kids,
				lifestyle,
			} = action.payload;
			return state.setIn(['categoryList', 'boy'],Immutable.fromJS(boy))
						.setIn(['categoryList', 'girl'],Immutable.fromJS(girl))
						.setIn(['categoryList', 'kids'],Immutable.fromJS(kids))
						.setIn(['categoryList', 'lifestyle'],Immutable.fromJS(lifestyle));
		}
		case SET_CURRENT_CATEGORY_ID:{
			return state.set('currentCateId',Immutable.fromJS(action.payload));
		}
		case SET_CURRENT_CHANNEL_ID:{
			return state.set('currentChannelId',Immutable.fromJS(action.payload));
		}
    }

    return state;
}