import { Reducer } from 'redux' ; import { Action } from '../actions/index' ; import { RESET } from '../actions/reset' ; export type ResetIndex < T extends object > = { [ K in keyof T ] : boolean ; } ; export function makeResetReducer < T extends object > ( r , resetIndex , defaultValue ) { return ( state , action ) => { if ( action . type === RESET ) { const newState = { ... state as object } as T ; Object . keys ( resetIndex ) . forEach ( ( key ) => { newState [ key ] = defaultValue [ key ] ; } ) ; return newState ; } else { return r ( state , action ) ; } } ; }