{"size": 1023, "ext": "js", "max_stars_repo_path": "src/reducers/AppReducer.js", "max_stars_repo_name": "bren-kam/wav-react", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/reducers/AppReducer.js", "max_issues_repo_name": "bren-kam/wav-react", "max_issues_repo_issues_event_min_datetime": "2021-01-05T13:31:07.000Z", "max_issues_repo_issues_event_max_datetime": "2021-01-05T13:31:07.000Z", "max_forks_repo_path": "src/reducers/AppReducer.js", "max_forks_repo_name": "ITsolution-git/wav-react", "max_forks_repo_forks_event_min_datetime": "2021-08-22T19:47:57.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-22T19:47:57.000Z"}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": 1, "avg_line_length": 29.2285714286, "max_line_length": 94, "alphanum_fraction": 0.6099706745}
import update from 'immutability-helper';

import appConstants from '../constants/AppConstants';
import initialState from '../constants/InitialState';

// this reducer used to store simple object data e. g signIn, signUp profile details and so on
// for complex objects use/create separate reducer
export default function appReducer (state = initialState.app, action) {
    const {
        type,
        dataType,
        data = {},
        error = ''
    } = action;

    const updateState = (isFetching = true, isSuccess = null) => {
        return update(state, {
            [dataType]: {
                $set: { isFetching, data, error, isSuccess }
            }
        });
    };

    switch (type) {
        case appConstants.INITIALIZE_REQUEST:
            return updateState(true);
        case appConstants.LOAD_DATA_SUCCESS:
            return updateState(false, true);
        case appConstants.LOAD_DATA_FAILURE:
            return updateState(false, false);
        default:
            return state

    }
}