{"size": 2514, "ext": "js", "max_stars_repo_path": "src/client/reducers/crudReducer.js", "max_stars_repo_name": "SDHarwick/CatSportsIQ", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/client/reducers/crudReducer.js", "max_issues_repo_name": "SDHarwick/CatSportsIQ", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/client/reducers/crudReducer.js", "max_forks_repo_name": "SDHarwick/CatSportsIQ", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 25.6530612245, "max_line_length": 91, "alphanum_fraction": 0.537788385}
import {
    ENTITY_CREATE,
    ENTITY_UPDATE,
    ENTITY_FETCH,
    SELECT_ENTITY_ITEM,
    ENTITY_DELETE,
    CLEAR_ENTITY_LIST
} from '../constants/actionType';


let initialState = {
    sites: {},
    products: [],
    selectedItem: {
        product: {},
    }
};

/**
 * A reducer takes two arguments, the current state and an action.
 */
export default function (state, action) {
    state = state || initialState;
    let newState;

    switch (action.type) {
        case ENTITY_CREATE:
            newState[action.entity] = Object.assign({}, state, action.data);
            return newState;

        case ENTITY_UPDATE:
            newState[action.entity] = Object.assign({}, state, action.data);
            return newState;

        case ENTITY_FETCH:
            newState[action.entity] = Object.assign({}, state, action.data);
            return newState;

        case ENTITY_DELETE:
            const data = Object.assign({}, state);
            newState[action.entity] = data.filter(data => data.id !== action.data.id);
            return newState;

        case SELECT_ENTITY_ITEM:
            newState.selectedItem[action.entity] = Object.assign({}, state, action.data);
            return newState;

        case CLEAR_ENTITY_LIST:
            newState[action.entity] = {};
            return newState;

        default:
            return state;
    }
}


// // Import custom components
// import {LOG_IN_SUCCESS, LOG_IN_FAILURE, LOG_OUT_SUCCESS} from '../constants/actionType';

// var initialState = {
//     token: null,
//     isAuthenticated: false,
//     isLoading: false
// };

// /**
//  * A reducer takes two arguments, the current state and an action.
//  */
// export default function (state, action) {
//     state = state || initialState;

//     switch (action.type) {
//         case LOG_IN_SUCCESS:
//             return Object.assign({}, state, {
//                 isAuthenticated: true,
//                 isLoading: false,
//                 token: action.data,
//             });

//         case LOG_IN_FAILURE:
//             return Object.assign({}, state, {
//                 isAuthenticated: false,
//                 isLoading: false,
//                 token: null,
//             });

//         case LOG_OUT_SUCCESS:
//             return Object.assign({}, state, {
//                 isAuthenticated: false,
//                 isLoading: true,
//                 token: null,
//             });

//         default:
//             return state;
//     }
// }