import { createMiniComponent , ComponentOptions , ComponentInstance , attachLogic , IProps , isComponent2 , } from '@goldfishjs/reactive-connect' ; import { silent } from '@goldfishjs/utils' ; import AppStore from '../store/AppStore' ; import ComponentStore from '../store/ComponentStore' ; param storeClass param componentOptions param options export default function createComponent < AS extends AppStore , CS extends ComponentStore < P , AS > , P extends IProps = { } , D = any , M extends tinyapp . IComponentMethods = { } > ( storeClass , componentOptions = { } , options ? ) { const enterKey = isComponent2 ? 'onInit' : 'didMount' ; attachLogic < typeof enterKey , Required < ComponentOptions < P , D , CS , M > > [ typeof enterKey ] > ( componentOptions , enterKey , 'after' , async function ( this ) { const store = this . store ! ; store . isInitLoading = true ; await silent . async ( ( ) => store . appStore . waitForInitDataReady ( ) ) ( ) ; try { await store . fetchInitData ( ) ; } catch ( e ) { throw e ; } finally { store . isInitLoading = false ; } } ) ; return createMiniComponent < P , CS , D , M > ( storeClass , componentOptions , { ... options , afterCreateStore : ( view , store ) => { options && options . afterCreateStore && options . afterCreateStore ( view , store ) ; store . appStore = ( getApp ( ) as any ) . store ; } , } ) ; }