import { App } from './app' ; import { ActionCreatorMap , ActionCreatorMapForEffects , Mutator , TriggerMapInput } from './types' ; import { typedKeyMirror } from './utils' ; export const typedActionCreators = < N extends string , P extends Record < string , Mutator < any > > > ( namespace , mutators , app ) => { const actionTypes = typedKeyMirror ( mutators , namespace ) ; const actionCreatorMap = { } as ActionCreatorMap < P > ; Object . keys ( mutators ) . forEach ( ( k ) => { const mutator = mutators [ k ] ; actionCreatorMap [ k ] = ( ... payload ) => app . store . dispatch ( { type : actionTypes [ k ] , payload , } ) ; } ) ; return [ actionCreatorMap , actionTypes ] as const ; } ; export const typedActionCreatorsForTriggers = < N extends string , P extends TriggerMapInput > ( namespace , triggerMap , app ) => { const prefix = `${ namespace }/triggers` as const ; const actionTypes = typedKeyMirror ( triggerMap , prefix ) ; const actionCreatorMap = { } as ActionCreatorMapForEffects < P > ; Object . keys ( triggerMap ) . forEach ( ( k ) => { actionCreatorMap [ k ] = ( ( ... payload ) => app . store . dispatch ( { type : actionTypes [ k ] , payload , } ) ) as any ; } ) ; return [ actionCreatorMap , actionTypes ] as const ; } ;