@@ -23,40 +23,50 @@ export default class Runner {
2323 }
2424
2525 async run ( ...cls ) {
26+ container . value (
27+ "__ojs_registrations" ,
28+ container . resolve ( "__ojs_registrations" ) ?? { }
29+ ) ;
30+
31+ const registrations = container . resolve ( "__ojs_registrations" ) ;
32+
2633 for ( let i = 0 ; i < cls . length ; i ++ ) {
2734 let c = cls [ i ] ;
2835 let instance ;
36+ const classKey = this . getClassKey ( c ) ;
2937
3038 if ( ! this . isClass ( c ) ) {
3139 // Functional component - always create new instance (not a singleton)
3240 instance = new Component ( c . name ) ;
3341 instance . render = c . bind ( instance ) ;
3442 } else {
35- // For classes, check if singleton exists in container
36- const classKey = this . getClassKey ( c ) ;
43+ if ( registrations [ classKey ] === "ongoing" ) {
44+ continue ;
45+ }
3746
3847 if ( container . has ( classKey ) ) {
39- // Retrieve existing singleton from container
4048 instance = container . resolve ( classKey ) ;
41-
42- // Skip if already registered (has __ojsRegistered flag)
4349 if ( instance . __ojsRegistered ) {
4450 continue ;
4551 }
4652 } else {
47- // Create new instance and register as singleton in container
4853 instance = new c ( ) ;
4954 container . singleton ( classKey , ( ) => instance , [ ] ) ;
55+ registrations [ classKey ] = "ongoing" ;
5056 }
5157 }
5258
5359 if ( instance instanceof Component ) {
5460 instance . getDeclaredListeners ( ) ;
5561 await instance . mount ( ) ;
62+ instance . __ojsRegistered = true ;
63+ registrations [ classKey ] = "completed" ;
5664 } else if ( instance instanceof Mediator || instance instanceof Listener ) {
5765 await instance . register ( ) ;
66+ registrations [ classKey ] = "completed" ;
5867 } else if ( instance instanceof Context ) {
5968 // Context instances don't need registration
69+ registrations [ classKey ] = "completed" ;
6070 } else {
6171 throw Error (
6272 `You can only pass declarations which extend Component, Mediator or Listener`
0 commit comments