categoryBReducer.js 2.16 KB
'use strict';

import InitialStateB from './categoryBInitialState';
import Immutable, {Map} from 'immutable';

const {
	SET_DELAY_EXPOSE_DATA,

    GET_CATEGORY_B_LIST_REQUEST,
    GET_CATEGORY_B_LIST_SUCCESS,
    GET_CATEGORY_B_LIST_FAILURE,

    GET_CATEGORY_B_SUBDETAIL_REQUEST,
    GET_CATEGORY_B_SUBDETAIL_SUCCESS,
    GET_CATEGORY_B_SUBDETAIL_FAILURE,

	SET_CURRENT_CATEGORY_B,
	SET_CURRENT_CHANNEL_B,

	SET_CURRENT_CATEGORY_B_SUBDETAIL_FROM_CACHE,

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

const initialStateB = new InitialStateB;

export default function categoryBReducer(state=initialStateB, action) {
    switch(action.type) {
    	case SET_DELAY_EXPOSE_DATA: {
    		return state.set('delayExposeData', action.payload);
    	}

		case GET_CATEGORY_B_LIST_REQUEST: {
			return state.set('isFetching', true)
				.set('categoryError', null);
		}
		case GET_CATEGORY_B_LIST_SUCCESS:{

			return state.set('categoryList', Immutable.fromJS(action.payload))
				.set('isFetching', false)
				.set('categoryError', null);
		}
		case GET_CATEGORY_B_LIST_FAILURE: {
			return state.set('isFetching', false)
				.set('categoryError', action.payload);
		}

		case GET_CATEGORY_B_SUBDETAIL_REQUEST: {
			return state.set('contentFetching', true);
		}
		case GET_CATEGORY_B_SUBDETAIL_SUCCESS:{

			let {key, data} = action.payload;
			return state.set('contentFetching', false)
				.set('currentSubCateData', Immutable.fromJS(data))
				.set('contentError', null)
				.setIn(['cacheSubCateData', key], Immutable.fromJS(data));

		}
		case GET_CATEGORY_B_SUBDETAIL_FAILURE: {
			return state.set('contentFetching', false).set('contentError', action.payload);
		}
		case SET_CURRENT_CATEGORY_B:{
			return state.set('currentCateId',action.payload.id)
				.set('currentCateValue',action.payload.value)
				.set('currentSubCateData',Map());

		}
		case SET_CURRENT_CHANNEL_B:{
			return state.set('currentChannelId',action.payload.id)
				.set('currentChannelValue', action.payload.value);
		}
		case SET_CURRENT_CATEGORY_B_SUBDETAIL_FROM_CACHE: {
			return state.set('contentFetching', false)
				.set('currentSubCateData', Immutable.fromJS(action.payload));
		}
    }

    return state;
}