@@ -12,7 +12,6 @@ export class DynamicHtmlAdapter implements IAdapter {
1212 public context : IContextNode
1313
1414 #observerByElement: Map < HTMLElement , MutationObserver > = new Map ( )
15- #elementByContext: WeakMap < IContextNode , HTMLElement > = new WeakMap ( )
1615 #contextByElement: Map < HTMLElement , IContextNode > = new Map ( )
1716
1817 #isStarted = false // ToDo: find another way to check if adapter is started
@@ -37,7 +36,7 @@ export class DynamicHtmlAdapter implements IAdapter {
3736 } )
3837
3938 // initial parsing without waiting for mutations in the DOM
40- this . _handleMutations ( [ ] , observer , element , this . #contextByElement. get ( element ) ! )
39+ this . _handleMutations ( element , this . #contextByElement. get ( element ) ! )
4140 } )
4241 this . #isStarted = true
4342 }
@@ -77,12 +76,15 @@ export class DynamicHtmlAdapter implements IAdapter {
7776 element
7877 )
7978
80- const observer = new MutationObserver ( ( mutations , observer ) =>
81- this . _handleMutations ( mutations , observer , element , context )
82- )
79+ const observer = new MutationObserver ( ( mutations , observer ) => {
80+ this . _handleMutations ( element , context )
81+
82+ if ( this . parser . shouldParseShadowDom ) {
83+ this . _observeShadowRoots ( mutations , observer )
84+ }
85+ } )
8386
8487 this . #observerByElement. set ( element , observer )
85- this . #elementByContext. set ( context , element )
8688 this . #contextByElement. set ( element , context )
8789
8890 // ToDo: duplicate code
@@ -99,8 +101,6 @@ export class DynamicHtmlAdapter implements IAdapter {
99101 }
100102
101103 private _handleMutations (
102- mutations : MutationRecord [ ] ,
103- observer : MutationObserver ,
104104 element : HTMLElement ,
105105 context : IContextNode
106106 ) {
@@ -111,17 +111,14 @@ export class DynamicHtmlAdapter implements IAdapter {
111111 this . treeBuilder . updateParsedContext ( context , parsedContext )
112112 this . treeBuilder . updateInsertionPoints ( context , insPoints )
113113 this . _removeOldChildContexts ( pairs , context )
114- this . _appendNewChildContexts ( pairs , context , observer )
114+ this . _appendNewChildContexts ( pairs , context )
115115
116- if ( this . parser . shouldParseShadowDom ) {
117- this . _observeShadowRoots ( mutations , observer )
118- }
116+ // ToDo: add warning about similar contexts
119117 }
120118
121119 private _appendNewChildContexts (
122120 childPairs : { element : HTMLElement ; contextName : string } [ ] ,
123- parentContext : IContextNode ,
124- observer : MutationObserver
121+ parentContext : IContextNode
125122 ) {
126123 for ( const { element, contextName } of childPairs ) {
127124 if ( ! this . #contextByElement. has ( element ) ) {
@@ -131,11 +128,10 @@ export class DynamicHtmlAdapter implements IAdapter {
131128 continue
132129 }
133130
134- this . #contextByElement. set ( element , childContext )
135131 this . treeBuilder . appendChild ( parentContext , childContext )
136132
137133 // initial parsing
138- this . _handleMutations ( [ ] , observer , element , childContext )
134+ this . _handleMutations ( element , childContext )
139135 }
140136 }
141137 }
0 commit comments