<commit_before>const UPDATE_MONITORS = 'scratch-gui/monitors/UPDATE_MONITORS';

const initialState = [];

const reducer = function (state, action) {
    if (typeof state === 'undefined') state = initialState;
    switch (action.type) {
    // Adds or updates monitors
    case UPDATE_MONITORS:
        return [...action.monitors, ...state];
    default:
        return state;
    }
};

reducer.updateMonitors = function (monitors) {
    return {
        type: UPDATE_MONITORS,
        monitors: monitors,
        meta: {
            throttle: 30
        }
    };
};

module.exports = reducer;
<commit_msg>throttle requests and fix code for merging new and old state<commit_after>const UPDATE_MONITORS = 'scratch-gui/monitors/UPDATE_MONITORS';

const initialState = [];

const reducer = function (state, action) {
    if (typeof state === 'undefined') state = initialState;
    switch (action.type) {
    // Adds or updates monitors
    case UPDATE_MONITORS:
        let newState = [...state];
        let updated = false;
        for (let i = 0; i < action.monitors.length; i++) {
            for (let j = 0; j < state.length; j++) {
                if (action.monitors[i].id == state[j].id) {
                    newState[j] = action.monitors[i];
                    updated = true;
                    continue;
                }
            }
            if (!updated) {
                newState.push(action.monitors[i]);
            }
            updated = false;
        }
        return newState;
    default:
        return state;
    }
};

reducer.updateMonitors = function (monitors) {
    return {
        type: UPDATE_MONITORS,
        monitors: monitors,
        meta: {
            throttle: 100
        }
    };
};

module.exports = reducer;

{'fraction_non_alphanumeric': 0.11560364464692482, 'fraction_numerical': 0.003986332574031891, 'mean_word_length': 1.8709150326797386, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '6926414', 'n_tokens_mistral': 542, 'n_tokens_neox': 513, 'n_words': 128}