import { Reducer } from 'redux' ; import { FETCH_END , REFRESH_VIEW } from '../../../../actions' ; import { GET_LIST , CREATE } from '../../../../core' ; interface ValidityRegistry { [ key ] : Date ; } const initialState = { } ; const validityReducer = ( previousState = initialState , { type , payload , requestPayload , meta } ) => { if ( type === REFRESH_VIEW ) { return initialState ; } if ( ! meta || ! meta . fetchResponse || meta . fetchStatus !== FETCH_END || meta . fromCache === true ) { return previousState ; } switch ( meta . fetchResponse ) { case GET_LIST : { if ( payload . validUntil ) { return { ... previousState , [ JSON . stringify ( requestPayload ) ] : payload . validUntil , } ; } else { const { [ JSON . stringify ( requestPayload ) ] : value , ... rest } = previousState ; return rest ; } } case CREATE : return initialState ; default : return previousState ; } } ; export default validityReducer ;