File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -82,23 +82,23 @@ function scan(node: Element = document.body) {
8282 )
8383}
8484
85- const elementLoader = new MutationObserver ( mutations => {
86- if ( ! dynamicElements . size ) return
87- for ( const mutation of mutations ) {
88- for ( const node of mutation . addedNodes ) {
89- if ( node instanceof Element ) scan ( node )
90- }
91- }
92- } )
85+ let elementLoader : MutationObserver
9386
94- let first = true
9587export function lazyDefine ( tagName : string , callback : ( ) => void ) {
9688 if ( ! dynamicElements . has ( tagName ) ) dynamicElements . set ( tagName , new Set < ( ) => void > ( ) )
9789 dynamicElements . get ( tagName ) ! . add ( callback )
9890
99- if ( first ) {
100- scan ( document . body )
91+ scan ( document . body )
92+
93+ if ( ! elementLoader ) {
94+ elementLoader = new MutationObserver ( mutations => {
95+ if ( ! dynamicElements . size ) return
96+ for ( const mutation of mutations ) {
97+ for ( const node of mutation . addedNodes ) {
98+ if ( node instanceof Element ) scan ( node )
99+ }
100+ }
101+ } )
101102 elementLoader . observe ( document , { subtree : true , childList : true } )
102- first = false
103103 }
104104}
You can’t perform that action at this time.
0 commit comments