1- import { Provider , Injector } from '@homebots/injector' ;
1+ import { Provider , Injector , TreeInjector } from '@homebots/injector' ;
22import { domReady } from './utils' ;
3- import { Application } from './application' ;
4- import { ChangeDetectorRef } from './change-detection/change-detection' ;
3+ import { ChangeDetector , ChangeDetectorRef } from './change-detection/change-detection' ;
54import { ReactiveChangeDetector } from './change-detection/reactive-change-detector' ;
65import { ForContainer } from './containers/for-container' ;
76import { IfContainer } from './containers/if-container' ;
@@ -25,14 +24,20 @@ export interface BootstrapOptions {
2524 useShadowDom ?: boolean ;
2625}
2726
27+ export interface Application {
28+ injector : Injector ;
29+ changeDetector : ChangeDetector ;
30+ check ( ) : Promise < void > ;
31+ }
32+
2833export class Bootstrap {
2934 private static promise : Promise < unknown > = domReady ( ) . then ( ( ) => Bootstrap . addDefaultRules ( ) ) ;
3035
3136 static whenReady ( fn : ( ...args : any [ ] ) => any ) {
3237 return ( this . promise = this . promise . then ( fn ) ) ;
3338 }
3439
35- static createApplication ( rootNode : HTMLElement = document . body , options ?: BootstrapOptions ) {
40+ static createApplication ( rootNode : HTMLElement = document . body , options ?: BootstrapOptions ) : Application {
3641 options = {
3742 ...defaultOptions ,
3843 ...options ,
@@ -41,14 +46,33 @@ export class Bootstrap {
4146 const { providers } = options ;
4247 providers . unshift ( defaultChangeDetector ) ;
4348
44- const application = new Application ( rootNode , providers ) ;
45- Bootstrap . whenReady ( ( ) => application . check ( ) ) ;
49+ const injector = Bootstrap . setupInjector ( rootNode , providers ) ;
50+ const changeDetector = injector . get ( ChangeDetectorRef ) ;
4651
4752 if ( options . useShadowDom !== undefined ) {
48- application . injector . get ( ShadowDomToggle ) . toggle ( options . useShadowDom ) ;
53+ injector . get ( ShadowDomToggle ) . toggle ( options . useShadowDom ) ;
4954 }
5055
51- return application ;
56+ const app = {
57+ injector,
58+ changeDetector,
59+ check ( ) {
60+ return changeDetector . markAsDirtyAndCheck ( ) ;
61+ } ,
62+ } ;
63+
64+ Bootstrap . whenReady ( ( ) => app . check ( ) ) ;
65+
66+ return app ;
67+ }
68+
69+ static setupInjector ( rootNode : HTMLElement , providers : Provider [ ] = [ ] ) {
70+ const injector = new TreeInjector ( ) ;
71+
72+ Injector . setInjectorOf ( rootNode , injector ) ;
73+ injector . provideAll ( providers ) ;
74+
75+ return injector ;
5276 }
5377
5478 static addDefaultRules ( ) {
0 commit comments