talentRankReducer.js 973 Bytes
'use strict';

import InitialState from './talentRankInitialState';
import Immutable, {List} from "immutable";

const {
    TALENT_RANK_REQUEST,
    MONTH_RANK_SUCCESS,
    TOTAL_RANK_SUCCESS,
    TALENT_RANK_FAILURE
} = require('../../constants/actionTypes').default;

const initialState = new InitialState;

export default function appReducer(state = initialState, action) {
    if (!(state instanceof InitialState)) return initialState.merge(state);

    switch (action.type) {
        case TALENT_RANK_REQUEST:
            return state.set('isFetching', true);
        case MONTH_RANK_SUCCESS:
            return state.set('isFetching', false)
            .set('monthRank', Immutable.fromJS(action.payload));
        case TOTAL_RANK_SUCCESS:
            return state.set('isFetching', false)
            .set('totalRank', Immutable.fromJS(action.payload));
        case TALENT_RANK_FAILURE:
            return state.set('isFetching', false);
    }

    return state;
}