import { AnyAction , Reducer } from 'redux' ; export const actionTypeHasNamespace = ( actionType ) => actionType . includes ( '/' ) ; export const createReducer = < S , R extends Record < string , Reducer < S > > > ( initialState , reducerMap ) => { return ( state = initialState , action ) : S => { const actionType = action . type ; const reducer = reducerMap [ actionType ] ; if ( reducer ) { return reducer ( state , action ) ; } else { return state ; } } ; } ; export type Mirrored < T extends Record < string , unknown > , N extends string > = { [ K in keyof T ] : `${ N }/${ string & K }` ; } ; export const typedKeyMirror = < T extends Record < string , unknown > , N extends string > ( keyMap , namespace ) => { const keyMirrored = { } as Mirrored < T , N > ; Object . keys ( keyMap ) . forEach ( ( k ) => ( keyMirrored [ k ] = `${ namespace }/${ k }` as const ) ) ; return keyMirrored ; } ;