import RuntimeModule from './runtimeModule' ; import { DEFAULT_APP_CONFIG } from './constants' ; import collectAppLifeCycle from './collectAppLifeCycle' ; import type { AppConfig , BuildConfig , Context } from './types' ; function mergeDefaultConfig ( defaultConfig , config ) { Object . keys ( defaultConfig ) . forEach ( key => { if ( typeof config [ key ] === 'object' && config [ key ] !== null ) { config [ key ] = mergeDefaultConfig ( defaultConfig [ key ] , config [ key ] ) ; } else if ( ! Object . prototype . hasOwnProperty . call ( config , key ) ) { config [ key ] = defaultConfig [ key ] ; } } ) ; return config ; } export default ( { loadRuntimeModules , createElement , runtimeAPI = { } , runtimeValue = { } } ) => { const createBaseApp = < T = AppConfig , P = BuildConfig , S = Context > ( appConfig , buildConfig , context , staticConfig ? ) => { appConfig = mergeDefaultConfig ( DEFAULT_APP_CONFIG , appConfig ) as T ; ( context as Context ) . createElement = createElement ; ( context as Context ) . enableRouter = ( runtimeValue as any ) . enableRouter ; const runtime = new RuntimeModule ( appConfig , buildConfig , context , staticConfig ) ; Object . keys ( runtimeAPI ) . forEach ( ( apiKey ) => { runtime . registerRuntimeAPI ( apiKey , runtimeAPI [ apiKey ] ) ; } ) ; Object . keys ( runtimeValue ) . forEach ( ( key ) => { runtime . setRuntimeValue ( key , runtimeValue [ key ] ) ; } ) ; loadRuntimeModules ( runtime ) ; collectAppLifeCycle ( appConfig ) ; return { runtime , appConfig } ; } ; return createBaseApp ; } ;