import type { PreModelAction } from '../actions/model' ; import { modelStore } from '../store/modelStore' ; import { toArgs } from '../utils/toArgs' ; import type { ActionCtx } from './defineModel' ; export interface EnhancedAction < State extends object > { ( payload ) : PreModelAction < State > ; } export const enhanceAction = < State extends object > ( ctx , actionName , consumer ) : EnhancedAction < State > => { const modelName = ctx . name ; const actionType = modelName + '.' + actionName ; const enhancedConsumer = ( state , action ) => { return consumer . apply ( ctx , [ state ] . concat ( action . payload ) as [ state : State , ... args : any [ ] ] ) ; } ; const fn = function ( ) { return modelStore . dispatch < PreModelAction < State , any [ ] > > ( { type : actionType , model : modelName , preModel : true , payload : toArgs ( arguments ) , consumer : enhancedConsumer , } ) ; } ; return fn ; } ;