export function MarchReducer(datas, action) {
    switch (action.type) {
        case 'ADD':
            return [
                ...datas,
                action.payload
            ]
        case 'ADD_ALL':
            return [
                ...datas,
                ...action.payload
            ]
        case 'REPLACE_ALL':
            return [
                ...action.payload
            ]
        case 'REPLACE_TREE':
            return [
                ...datas.filter(data => data.categorie_ord !== -42),
                ...action.payload
            ]
        case 'CLEAR':
            return []
        case 'REMOVE':
            return datas.filter(data => data.id !== action.payload)
        case 'REMOVE_TREE':
            return datas.filter(data => data.categorie_ord !== -42)
        case 'UPDATE_OR_ADD':
            const index = datas.findIndex(data => data.id === action.payload.id)
            if (index === -1) {
                return [
                    ...datas,
                    action.payload
                ]
            } else {
                datas[index] = action.payload
                return [...datas]
            }
        case 'SORT':
            return datas.sort(action.payload)
        default:
            throw new Error()
    }
}
