<commit_before>'use strict';

var receiveUser = (nextState, action) => {
    nextState.userData = action.json;
    return nextState;
};

var receiveImage = (nextState, action) => {
    nextState.resp = action.json;
    return nextState;
};

var handleAjaxStart = (nextState, action) => {
    nextState.isFetching = true;
    nextState.fetchingWhat = action.what;
    return nextState;
};

var handleAjaxDone = (nextState, action) => {
    nextState.isFetching = false;
    nextState.fetchingWhat = '';
    switch (action.what) {
        case 'allImages': return {nextState, images: action.json};
        default: return nextState;
    }

};

var handleError = (nextState, action) => {
    nextState.err = action.err;
    nextState.isFetching = false;
    nextState.fetchingWhat = '';
    return nextState;
};

export function profileReducer(state, action) {
    if (typeof state === 'undefined') {
        return {
            clicked: false,
            err: null,
            msg: '',
            username: '',
            userData: null,
            isFetching: false,
            fetchingWhat: ''
        };
    }

    // State copy done here
    let nextState = Object.assign({}, state);

    switch (action.type) {
        case 'AJAX_START': return handleAjaxStart(nextState, action);
        case 'BUTTON_CLICKED': return Object.assign(
                nextState, {clicked: true});
        case 'ERROR': return handleError(nextState, action);
        case 'FETCH_USER':
        case 'RECEIVE_USER': return receiveUser(nextState, action);
        case 'RECEIVE_IMAGE': return receiveImage(nextState, action);
        case 'AJAX_DONE': return handleAjaxDone(nextState, action);
        default: return nextState;
    }
}<commit_msg>Added isFetching and images to the state.<commit_after>'use strict';

var receiveUser = (nextState, action) => {
    nextState.userData = action.json;
    return nextState;
};

var receiveImage = (nextState, action) => {
    nextState.resp = action.json;
    return nextState;
};

var handleAjaxStart = (nextState, action) => {
    nextState.isFetching = true;
    nextState.fetchingWhat = action.what;
    return nextState;
};

var handleAjaxDone = (nextState, action) => {
    nextState.isFetching = false;
    nextState.fetchingWhat = '';
    switch (action.what) {
        case 'allImages': return {nextState, images: action.json};
        default: return nextState;
    }

};

var handleError = (nextState, action) => {
    nextState.err = action.err;
    nextState.isFetching = false;
    nextState.fetchingWhat = '';
    return nextState;
};

export function profileReducer(state, action) {
    if (typeof state === 'undefined') {
        return {
            clicked: false,
            err: null,
            fetchingWhat: '',
            images: [],
            isFetching: false,
            msg: '',
            userData: null,
            username: ''
        };
    }

    // State copy done here
    let nextState = Object.assign({}, state);

    switch (action.type) {
        case 'AJAX_START': return handleAjaxStart(nextState, action);
        case 'BUTTON_CLICKED': return Object.assign(
                nextState, {clicked: true});
        case 'ERROR': return handleError(nextState, action);
        case 'FETCH_USER':
        case 'RECEIVE_USER': return receiveUser(nextState, action);
        case 'RECEIVE_IMAGE': return receiveImage(nextState, action);
        case 'AJAX_DONE': return handleAjaxDone(nextState, action);
        default: return nextState;
    }
}
{'fraction_non_alphanumeric': 0.11939875212705615, 'fraction_numerical': 0.0, 'mean_word_length': 2.5989795918367347, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1647193', 'n_tokens_mistral': 1042, 'n_tokens_neox': 1039, 'n_words': 255}