<commit_before>import { fetchApi as fetch } from '../utils'
import { CMD_RESET as WS_CMD_RESET } from './websocket'
import reduceList, * as listActions from './utils/list'

export const WS_MSG = 'FLOWS_WS_MSG'
export const UPDATE_FILTER = 'FLOWS_UPDATE_FLOW_FILTER'
export const UPDATE_HIGHLIGHT = 'FLOWS_UPDATE_FLOW_HIGHLIGHT'
export const UPDATE_SORT = 'FLOWS_UPDATE_FLOW_SORT'
export const SELECT = 'FLOWS_SELECT'
export const REQUEST_ACTION = 'FLOWS_REQUEST_ACTION'

const defaultState = {
    selected: [],
    sorter: {},
    filter: null,
    highlight: null,
    list: reduceList(undefined, { type: Symbol('FLOWS_INIT_LIST') }),
}

export default function reduce(state = defaultState, action) {
    switch (action.type) {

        case UPDATE_FILTER:
            return {
                ...state,
                filter: action.filter,
                list: reduceList(state.list, listActions.updateFilter(action.filter ? Filt.parse(action.filter) : () => true)),
            }

        case UPDATE_HIGHLIGHT:
            return {
                ...state,
                highlight: action.highlight,
            }

        case UPDATE_SORTER:
            const { column, desc, sortKeyFun } = action
            return {
                ...state,
                sorter: { column, desc },
                list: reduceList(state.list, listActions.updateSorter((a, b) => {
                    const ka = sortKeyFun(a)
                    const kb = sortKeyFun(b)
                    if (ka > kb) {
                        return desc ? -1 : 1
                    }
                    if (ka < kb) {
                        return desc ? 1 : -1
                    }
                    return 0
                })),
            }

        case SELECT:
            return {
                ...state,
                selected: [action.id],
            }

        case WS_MSG:
            return {
                ...state,
                list: reduceList(state.list, listActions.handleWsMsg(action.msg)),
            }

        default:
            return state
    }
}

/**
 * @public
 */
export function updateFilter(filter) {
    return { type: UPDATE_FILTER, filter }
}
<commit_msg>[web] flows.makeFun<commit_after>import { fetchApi as fetch } from '../utils'
import { CMD_RESET as WS_CMD_RESET } from './websocket'
import reduceList, * as listActions from './utils/list'

export const WS_MSG = 'FLOWS_WS_MSG'
export const UPDATE_FILTER = 'FLOWS_UPDATE_FLOW_FILTER'
export const UPDATE_HIGHLIGHT = 'FLOWS_UPDATE_FLOW_HIGHLIGHT'
export const UPDATE_SORT = 'FLOWS_UPDATE_FLOW_SORT'
export const SELECT = 'FLOWS_SELECT'
export const REQUEST_ACTION = 'FLOWS_REQUEST_ACTION'

const defaultState = {
    selected: [],
    sorter: {},
    filter: null,
    highlight: null,
    list: reduceList(undefined, { type: Symbol('FLOWS_INIT_LIST') }),
}

export default function reduce(state = defaultState, action) {
    switch (action.type) {

        case UPDATE_FILTER:
            return {
                ...state,
                filter: action.filter,
                list: reduceList(state.list, listActions.updateFilter(makeFilterFun(action.filter))),
            }

        case UPDATE_HIGHLIGHT:
            return {
                ...state,
                highlight: action.highlight,
            }

        case UPDATE_SORTER:
            return {
                ...state,
                sorter: { column: action.column, desc: action.desc },
                list: reduceList(state.list, listActions.updateSorter(makeSortFun(action.sortKeyFun, action.desc))),
            }

        case SELECT:
            return {
                ...state,
                selected: [action.id],
            }

        case WS_MSG:
            return {
                ...state,
                list: reduceList(state.list, listActions.handleWsMsg(action.msg)),
            }

        default:
            return state
    }
}

function makeFilterFun(filter) {
    return filter ? Filt.parse(filter) : () => true
}

function makeSortFun(sortKeyFun, desc) {
    return (a, b) => {
        const ka = sortKeyFun(a)
        const kb = sortKeyFun(b)
        if (ka > kb) {
            return desc ? -1 : 1
        }
        if (ka < kb) {
            return desc ? 1 : -1
        }
        return 0
    }
}

/**
 * @public
 */
export function updateFilter(filter) {
    return { type: UPDATE_FILTER, filter }
}

{'fraction_non_alphanumeric': 0.10324483775811209, 'fraction_numerical': 0.002269117313365101, 'mean_word_length': 1.674757281553398, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '2101789', 'n_tokens_mistral': 1322, 'n_tokens_neox': 1216, 'n_words': 290}