@@ -37,22 +37,27 @@ class DDGRuntimeChecks extends HTMLElement {
37
37
this . #connected = false
38
38
}
39
39
40
+ /**
41
+ * This method is called once and externally so has to remain public.
42
+ **/
40
43
setTagName ( tagName ) {
41
44
this . #tagName = tagName
45
+ // Clear the method so it can't be called again
46
+ delete this . setTagName
42
47
}
43
48
44
49
connectedCallback ( ) {
45
50
// Solves re-entrancy issues from React
46
51
if ( this . #connected) return
47
52
this . #connected = true
48
- if ( ! this . transplantElement ) {
53
+ if ( ! this . # transplantElement) {
49
54
// Restore the 'this' object with the DDGRuntimeChecks prototype as sometimes pages will overwrite it.
50
55
Object . setPrototypeOf ( this , DDGRuntimeChecks . prototype )
51
56
}
52
- this . transplantElement ( )
57
+ this . # transplantElement( )
53
58
}
54
59
55
- monitorProperties ( el ) {
60
+ # monitorProperties ( el ) {
56
61
// Mutation oberver and observedAttributes don't work on property accessors
57
62
// So instead we need to monitor all properties on the prototypes and forward them to the real element
58
63
let propertyNames = [ ]
@@ -85,7 +90,7 @@ class DDGRuntimeChecks extends HTMLElement {
85
90
* The element has been moved to the DOM, so we can now reflect all changes to a real element.
86
91
* This is to allow us to interrogate the real element before it is moved to the DOM.
87
92
*/
88
- transplantElement ( ) {
93
+ # transplantElement ( ) {
89
94
// Creeate the real element
90
95
const el = initialCreateElement . call ( document , this . #tagName)
91
96
@@ -134,7 +139,7 @@ class DDGRuntimeChecks extends HTMLElement {
134
139
this . insertAdjacentElement ( 'afterend' , el )
135
140
} catch ( e ) { console . warn ( e ) }
136
141
137
- this . monitorProperties ( el )
142
+ this . # monitorProperties( el )
138
143
// TODO pollyfill WeakRef
139
144
this . #el = new WeakRef ( el )
140
145
@@ -144,13 +149,15 @@ class DDGRuntimeChecks extends HTMLElement {
144
149
} , elementRemovalTimeout )
145
150
}
146
151
147
- getElement ( ) {
152
+ # getElement ( ) {
148
153
return this . #el?. deref ( )
149
154
}
150
155
156
+ /* Native DOM element methods we're capturing to supplant values into the constructed node or store data for. */
157
+
151
158
setAttribute ( name , value ) {
152
159
if ( shouldFilterKey ( this . #tagName, 'attribute' , name ) ) return
153
- const el = this . getElement ( )
160
+ const el = this . # getElement( )
154
161
if ( el ) {
155
162
return el . setAttribute ( name , value )
156
163
}
@@ -159,7 +166,7 @@ class DDGRuntimeChecks extends HTMLElement {
159
166
160
167
removeAttribute ( name ) {
161
168
if ( shouldFilterKey ( this . #tagName, 'attribute' , name ) ) return
162
- const el = this . getElement ( )
169
+ const el = this . # getElement( )
163
170
if ( el ) {
164
171
return el . removeAttribute ( name )
165
172
}
@@ -168,7 +175,7 @@ class DDGRuntimeChecks extends HTMLElement {
168
175
169
176
addEventListener ( ...args ) {
170
177
if ( shouldFilterKey ( this . #tagName, 'listener' , args [ 0 ] ) ) return
171
- const el = this . getElement ( )
178
+ const el = this . # getElement( )
172
179
if ( el ) {
173
180
return el . addEventListener ( ...args )
174
181
}
@@ -177,7 +184,7 @@ class DDGRuntimeChecks extends HTMLElement {
177
184
178
185
removeEventListener ( ...args ) {
179
186
if ( shouldFilterKey ( this . #tagName, 'listener' , args [ 0 ] ) ) return
180
- const el = this . getElement ( )
187
+ const el = this . # getElement( )
181
188
if ( el ) {
182
189
return el . removeEventListener ( ...args )
183
190
}
@@ -200,15 +207,15 @@ class DDGRuntimeChecks extends HTMLElement {
200
207
}
201
208
202
209
remove ( ) {
203
- const el = this . getElement ( )
210
+ const el = this . # getElement( )
204
211
if ( el ) {
205
212
return el . remove ( )
206
213
}
207
214
return super . remove ( )
208
215
}
209
216
210
217
removeChild ( child ) {
211
- const el = this . getElement ( )
218
+ const el = this . # getElement( )
212
219
if ( el ) {
213
220
return el . removeChild ( child )
214
221
}
0 commit comments