@@ -41,7 +41,8 @@ export default class Component {
4141 rendered : "rendered" , // component ui is computed
4242 rerendered : "rerendered" , // component was ui was recomputed.
4343 mounted : "mounted" , // the component is now on the dom
44- unmounted : "unmounted" , // removed from the repository
44+ unmounted : "unmounted" , // removed from the repository,
45+ childrenMounted : "childrenMounted" , // used when rerendering completes
4546 } ;
4647
4748 /**
@@ -101,6 +102,12 @@ export default class Component {
101102 if ( component ) component . handleMounted ( ) ;
102103 } ) ;
103104
105+ this . on ( this . EVENTS . childrenMounted , ( componentId ) => {
106+ let repo = container . resolve ( "repository" ) ;
107+ let component = repo . findComponent ( componentId ) ;
108+ if ( component ) component . handleChildrenMounted ( ) ;
109+ } ) ;
110+
104111 /**
105112 * Compare two Nodes
106113 */
@@ -435,9 +442,10 @@ export default class Component {
435442 } else {
436443 reconciler . reconcile ( markup , e . childNodes [ 0 ] ) ;
437444 }
438- }
439445
440- this . emit ( this . EVENTS . rerendered , this . id ) ;
446+ this . emit ( this . EVENTS . childrenMounted , this . id ) ;
447+ this . emit ( this . EVENTS . rerendered , this . id ) ;
448+ }
441449 } ) ;
442450
443451 queueMicrotask ( cleanupDisconnectedComponents ) ;
@@ -593,4 +601,26 @@ export default class Component {
593601 if ( component ) component . emit ( this . EVENTS . mounted , component . id ) ;
594602 } ) ;
595603 }
604+
605+ handleChildrenMounted ( ) {
606+ if ( ! this . mounted ) return ;
607+
608+ let markups = this . markup ( ) ;
609+
610+ let root = markups [ 0 ] ;
611+
612+ if ( ! root || ! root . isConnected ) return ;
613+
614+ let children = getOjsChildren ( root ) ;
615+
616+ children . forEach ( ( child ) => {
617+ let component = container
618+ . resolve ( "repository" )
619+ . findComponent ( child . getAttribute ( "ojs-uid" ) ) ;
620+
621+ if ( component && ! component . mounted ) {
622+ component . emit ( this . EVENTS . mounted , component . id ) ;
623+ }
624+ } ) ;
625+ }
596626}
0 commit comments