import { UPDATE_REPORTS , } from '../constants/actionTypes' ; import { StoreAction } from '../actions' ; export interface Data { id : unknown ; } export interface ReportsState { data : Data [ ] ; } const initialState = { data : [ ] , } ; export function reports ( state = initialState , action ) { if ( action . type !== UPDATE_REPORTS ) return state ; const request = action . request ; switch ( request . type ) { case 'list' : return { ... state , data : request . data , } ; case 'add' : return { ... state , data : [ ... state . data , request . data ] , } ; case 'remove' : return { ... state , data : state . data . filter ( ( d ) => d . id !== request . id ) , } ; default : return state ; } }