import { namespaced } from './namespaced' ; import { KeyMap } from '../typings/utils' ; import { ActionTypes } from '../typings/commons' ; import { ActionsSrc , ActionCreators , Actions } from '../typings/createActions' ; function createActions < T extends KeyMap & ActionsSrc < T > > ( actionsSrc , namespace ) { if ( namespaced [ namespace ] !== undefined && process . env . NODE_ENV !== 'development' ) { throw new Error ( `redux-aggregate: conflict namespace -> ${ namespace }` ) ; } else { namespaced [ namespace ] = namespace ; } const types = { } ; const creators = { } ; const __srcmap__ = { } ; Object . keys ( actionsSrc ) . forEach ( key => { const type = `${ namespace }${ key }` ; types [ key ] = type ; creators [ key ] = ( payload ? ) => ( { type , payload : actionsSrc [ key ] ( payload ) } ) ; __srcmap__ [ type ] = actionsSrc [ key ] ; } ) ; return { __namespace__ : namespace , __srcmap__ : __srcmap__ as T , types : types as ActionTypes < T > , creators : creators as ActionCreators < T > } ; } export { createActions } ;