import { assign } from './actions' ; import { createMachine } from './Machine' ; import type { EventObject , BaseActionObject } from './types' ; import { mapValues } from './utils' ; import { Cast , UnionFromCreatorsReturnTypes , FinalModelCreators , Model , ModelCreators , Prop , IsNever } from './model.types' ; export function createModel < TContext , TEvent extends EventObject , TAction extends BaseActionObject = BaseActionObject > ( initialContext ) ; export function createModel < TContext , TModelCreators extends ModelCreators < TModelCreators > , TFinalModelCreators = FinalModelCreators < TModelCreators > , TComputedEvent = UnionFromCreatorsReturnTypes < Prop < TFinalModelCreators , 'events' > > , TComputedAction = UnionFromCreatorsReturnTypes < Prop < TFinalModelCreators , 'actions' > > > ( initialContext , creators ) ; export function createModel ( initialContext , creators ? ) { const eventCreators = creators ?. events ; const actionCreators = creators ?. actions ; const model = { initialContext , assign , events : ( eventCreators ? mapValues ( eventCreators , ( fn , eventType ) => ( ... args ) => ( { ... fn ( ... args ) , type : eventType } ) ) : undefined ) as any , actions : actionCreators ? mapValues ( actionCreators , ( fn , actionType ) => ( ... args ) => ( { ... fn ( ... args ) , type : actionType } ) ) : undefined , reset : ( ) => assign ( initialContext ) , createMachine : ( config , implementations ) => { return createMachine ( 'context' in config ? config : { ... config , context : initialContext } , implementations ) ; } } ; return model ; }