<commit_before>import { ActionType, ToAction } from "../actions/Action";
import { HostPeerAction, IAddSignalDataAction, IClearSignalDataAction, ICreatePeerAction, ISetPeerStatusAction } from "../actions/HostPeerActions";
import { IHostPeerState } from "../redux/State";
import { DataType } from "../utils/Definitions";
import { addSignalData } from "../utils/ReduxUtils";

const initialHostPeerState: IHostPeerState = {
    hostPeers: [],
};

const hostPeerState = (state: IHostPeerState = initialHostPeerState, action: ToAction<HostPeerAction>) => {
    const types = ActionType.hostPeerAction;

    switch (action.type) {
        case types.addClientSignalDataAction:
            return addSignalData(state, action as IAddSignalDataAction, DataType.CLIENT);

        case types.addHostSignalDataAction:
            return addSignalData(state, action as IAddSignalDataAction, DataType.HOST);

        case types.clearSignalDataAction:
            return Object.assign({}, state, {
                hostPeers: state.hostPeers.map((peer) => {
                    if (peer.clientID === (action as IClearSignalDataAction).id) {
                        Object.assign(peer, {
                            hostSignalData: [],
                        });
                    }
                    else {
                        return peer;
                    }
                }),
            });

        case types.createPeerAction:
            return Object.assign({}, state, {
                hostPeers: state.hostPeers.concat({
                    peerStatus: false,
                    clientID: (action as ICreatePeerAction).clientID,
                    clientSignalData: (action as ICreatePeerAction).signalData,
                    hostSignalData: [],
                }),
            });

        case types.setPeerStatusAction:
            return Object.assign({}, state, {
                hostPeers: state.hostPeers.map((peer) => {
                    if (peer.clientID === (action as ISetPeerStatusAction).clientID) {
                        return Object.assign(peer, {
                            peerStatus: (action as ISetPeerStatusAction).status,
                        });
                    }
                }),
            });

        default:
            return state;
    }
};

export default hostPeerState;<commit_msg>Fixing defect - overwriting peers on status change<commit_after>import { ActionType, ToAction } from "../actions/Action";
import { HostPeerAction, IAddSignalDataAction, IClearSignalDataAction, ICreatePeerAction, ISetPeerStatusAction } from "../actions/HostPeerActions";
import { IHostPeerState } from "../redux/State";
import { DataType } from "../utils/Definitions";
import { addSignalData } from "../utils/ReduxUtils";

const initialHostPeerState: IHostPeerState = {
    hostPeers: [],
};

const hostPeerState = (state: IHostPeerState = initialHostPeerState, action: ToAction<HostPeerAction>) => {
    const types = ActionType.hostPeerAction;

    switch (action.type) {
        case types.addClientSignalDataAction:
            return addSignalData(state, action as IAddSignalDataAction, DataType.CLIENT);

        case types.addHostSignalDataAction:
            return addSignalData(state, action as IAddSignalDataAction, DataType.HOST);

        case types.clearSignalDataAction:
            return Object.assign({}, state, {
                hostPeers: state.hostPeers.map((peer) => {
                    if (peer.clientID === (action as IClearSignalDataAction).id) {
                        Object.assign(peer, {
                            hostSignalData: [],
                        });
                    }
                    else {
                        return peer;
                    }
                }),
            });

        case types.createPeerAction:
            return Object.assign({}, state, {
                hostPeers: state.hostPeers.concat({
                    peerStatus: false,
                    clientID: (action as ICreatePeerAction).clientID,
                    clientSignalData: (action as ICreatePeerAction).signalData,
                    hostSignalData: [],
                }),
            });

        case types.setPeerStatusAction:
            return Object.assign({}, state, {
                hostPeers: state.hostPeers.map((peer) => {
                    if (peer.clientID === (action as ISetPeerStatusAction).clientID) {
                        return Object.assign(peer, {
                            peerStatus: (action as ISetPeerStatusAction).status,
                        });
                    }

                    return peer;
                }),
            });

        default:
            return state;
    }
};

export default hostPeerState;
{'fraction_non_alphanumeric': 0.09938934512528953, 'fraction_numerical': 0.0, 'mean_word_length': 1.6988636363636365, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '6068561', 'n_tokens_mistral': 1179, 'n_tokens_neox': 1125, 'n_words': 239}