detailReducer.js 2.04 KB
'use strict';

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

const {
	BRAND_INFO_REQUEST,
	BRAND_INFO_SUCCESS,
	BRAND_INFO_FAILURE,

	JUMP_WITH_URL,
	SET_BRAND_ID,
	SET_GENDER,
	SET_UDID,
	
	BRADN_FAV_REQUEST,
	BRADN_FAV_SUCCESS,
	BRADN_FAV_FAILURE,

	NEW_ARRIVE_REQUEST,
	NEW_ARRIVE_SUCCESS,
	NEW_ARRIVE_FAILURE,

	ARTICLE_BY_BRAND_REQUEST,
	ARTICLE_BY_BRAND_SUCCESS,
	ARTICLE_BY_BRAND_FAILURE,

	ADD_FAVORITE_REQUEST,
	ADD_FAVORITE_SUCCESS,
	ADD_FAVORITE_FAILURE,

	CANCEL_FAVORITE_REQUEST,
	CANCEL_FAVORITE_SUCCESS,
	CANCEL_FAVORITE_FAILURE,

	PRAISE_ARTICLE_REQUEST,
    PRAISE_ARTICLE_SUCCESS,
    PRAISE_ARTICLE_FAILURE,

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

const initialState = new InitialState;

export default function plustarReducer(state=initialState, action) {
    switch(action.type) {
        case BRAND_INFO_REQUEST: {
			return state.setIn(['brandInfo', 'isFetching'], true)
			.setIn(['brandInfo', 'error'], null);
        }
		case BRAND_INFO_SUCCESS: {
			return state.setIn(['brandInfo', 'detail'], Immutable.fromJS(action.payload))
			.setIn(['brandInfo', 'isFetching'], false)
			.setIn(['brandInfo', 'error'], null);
		}
		case BRAND_INFO_FAILURE: {
			return state.setIn(['brandInfo', 'isFetching'], false)
			.setIn(['brandInfo', 'error'], action.payload);
		}
        case SET_BRAND_ID:{
        	return state.set('brandId', action.payload);
        }
        case SET_UDID:{
        	return state.set('udid', action.payload);
        }
        case NEW_ARRIVE_SUCCESS:{
        	return state.set('productList', Immutable.fromJS(action.payload));
        }
        case ARTICLE_BY_BRAND_SUCCESS:{
        	return state.set('articleList', Immutable.fromJS(action.payload));
        }
        case PRAISE_ARTICLE_SUCCESS:{
        	console.log("chenlin", "PRAISE_ARTICLE_SUCCESS:" + JSON.stringify(action.payload));
        }
        case PRAISE_ARTICLE_FAILURE:{
        	console.log("chenlin", "PRAISE_ARTICLE_FAILURE:" + JSON.stringify(action.payload));
        }        
    }

    return state;
}