<commit_before>import { NodeLogic }      from '../components/NodeLogic';

type StateType = NodeLogic[] ;
const initialState: StateType = [];

export const nodeListReducer = (state: StateType, action: any) => {
    if (state === undefined) {
        return initialState;
    } else {
        switch (action.type) {
            case 'ADD_NODES':
                console.log('in ADD_NODES');
                // who is the parent common to all nodes from payload
                const payloadNodes: NodeLogic[] = action.payload;
                const firstParentId: number = payloadNodes[0].dbrecord.child_of;
                const sameParent = (node: NodeLogic) => {
                    return firstParentId === node.dbrecord.child_of;
                };
                const payloadNodesHaveCommonParent = payloadNodes.every(sameParent);
                if (!payloadNodesHaveCommonParent) {
                    throw new Error('Payload nodes don\'t have one common parent');
                }
                // get position of parent in old state
                const parentIndex = state.findIndex((node: NodeLogic) => {
                    return node.dbrecord.id === firstParentId;
                });
                if (parentIndex === -1) {
                    return payloadNodes;
                } else {

                    // the new state is old state from 0 up to and including the
                    // parent, followed by the nodes from payload, followed by
                    // the remaining nodes from old state
                    const begin = state.slice(0, parentIndex + 1);
                    const middle = payloadNodes;
                    const end = state.slice(parentIndex + 1);
                    return begin.concat(middle).concat(end);

                }
            case 'FETCH_CHILD_NODES': {
                // should fire a query to get child nodes of node action.payload
                console.log('in FETCH_CHILD_NODES');
                const node: NodeLogic = action.payload.node;
                node.fetchChildNodes(action.payload.dispatch);
            }
            case 'TOGGLE_ISEXPANDED':
                console.log('in TOGGLE_ISEXPANDED');
                return state.map((node) => {
                    if (action.payload === node.dbrecord.id) {
                        //return Object.assign({}, node, {isexpanded: !node.isexpanded});
                        return Object.assign(new NodeLogic(node.dbrecord), node, {isexpanded: !node.isexpanded});
                    } else {
                        return node;
                    }
                });
            default: {<commit_msg>resolved linter error about fallthrough case that happened in one of the reducer cases<commit_after>import { NodeLogic }      from '../components/NodeLogic';

type StateType = NodeLogic[] ;
const initialState: StateType = [];

export const nodeListReducer = (state: StateType, action: any) => {
    if (state === undefined) {
        return initialState;
    } else {
        switch (action.type) {
            case 'ADD_NODES':
                console.log('in ADD_NODES');
                // who is the parent common to all nodes from payload
                const payloadNodes: NodeLogic[] = action.payload;
                const firstParentId: number = payloadNodes[0].dbrecord.child_of;
                const sameParent = (node: NodeLogic) => {
                    return firstParentId === node.dbrecord.child_of;
                };
                const payloadNodesHaveCommonParent = payloadNodes.every(sameParent);
                if (!payloadNodesHaveCommonParent) {
                    throw new Error('Payload nodes don\'t have one common parent');
                }
                // get position of parent in old state
                const parentIndex = state.findIndex((node: NodeLogic) => {
                    return node.dbrecord.id === firstParentId;
                });
                if (parentIndex === -1) {
                    return payloadNodes;
                } else {

                    // the new state is old state from 0 up to and including the
                    // parent, followed by the nodes from payload, followed by
                    // the remaining nodes from old state
                    const begin = state.slice(0, parentIndex + 1);
                    const middle = payloadNodes;
                    const end = state.slice(parentIndex + 1);
                    return begin.concat(middle).concat(end);

                }
            case 'FETCH_CHILD_NODES': {
                // should fire a query to get child nodes of node action.payload
                console.log('in FETCH_CHILD_NODES');
                const node: NodeLogic = action.payload.node;
                // beware: side effects happen here:
                node.fetchChildNodes(action.payload.dispatch);
                return state;
            }
            case 'TOGGLE_ISEXPANDED':
                console.log('in TOGGLE_ISEXPANDED');
                return state.map((node) => {
                    if (action.payload === node.dbrecord.id) {
                        //return Object.assign({}, node, {isexpanded: !node.isexpanded});
                        return Object.assign(new NodeLogic(node.dbrecord), node, {isexpanded: !node.isexpanded});
                    } else {
                        return node;
                    }
                });
            default: {
{'fraction_non_alphanumeric': 0.09192660550458716, 'fraction_numerical': 0.0022018348623853213, 'mean_word_length': 1.462059620596206, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4531035', 'n_tokens_mistral': 1375, 'n_tokens_neox': 1270, 'n_words': 368}