export function SimpleReducer(datas, action) {
    switch (action.type) {
        case 'ADD':
            return [
                ...datas,
                action.payload
            ]
        case 'REMOVE':
            return datas.filter(data => data.id !== action.payload)
        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()
    }
}