Skip to content

Replace private method support with _ for now #321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions src/features/runtime-checks.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ class DDGRuntimeChecks extends HTMLElement {
// Solves re-entrancy issues from React
if (this.#connected) return
this.#connected = true
if (!this.#transplantElement) {
if (!this._transplantElement) {
// Restore the 'this' object with the DDGRuntimeChecks prototype as sometimes pages will overwrite it.
Object.setPrototypeOf(this, DDGRuntimeChecks.prototype)
}
this.#transplantElement()
this._transplantElement()
}

#monitorProperties (el) {
_monitorProperties (el) {
// Mutation oberver and observedAttributes don't work on property accessors
// So instead we need to monitor all properties on the prototypes and forward them to the real element
let propertyNames = []
Expand Down Expand Up @@ -93,7 +93,7 @@ class DDGRuntimeChecks extends HTMLElement {
* The element has been moved to the DOM, so we can now reflect all changes to a real element.
* This is to allow us to interrogate the real element before it is moved to the DOM.
*/
#transplantElement () {
_transplantElement () {
// Creeate the real element
const el = initialCreateElement.call(document, this.#tagName)

Expand Down Expand Up @@ -153,7 +153,7 @@ class DDGRuntimeChecks extends HTMLElement {
this.insertAdjacentElement('afterend', el)
} catch (e) { console.warn(e) }

this.#monitorProperties(el)
this._monitorProperties(el)
// TODO pollyfill WeakRef
this.#el = new WeakRef(el)

Expand All @@ -163,14 +163,14 @@ class DDGRuntimeChecks extends HTMLElement {
}, elementRemovalTimeout)
}

#getElement () {
_getElement () {
return this.#el?.deref()
}

/* Native DOM element methods we're capturing to supplant values into the constructed node or store data for. */

set src (value) {
const el = this.#getElement()
const el = this._getElement()
if (el) {
el.src = value
return
Expand All @@ -179,7 +179,7 @@ class DDGRuntimeChecks extends HTMLElement {
}

get src () {
const el = this.#getElement()
const el = this._getElement()
if (el) {
return el.src
}
Expand All @@ -196,7 +196,7 @@ class DDGRuntimeChecks extends HTMLElement {
if (supportedSinks.includes(name)) {
return this[name]
}
const el = this.#getElement()
const el = this._getElement()
if (el) {
return el.getAttribute(name)
}
Expand All @@ -209,7 +209,7 @@ class DDGRuntimeChecks extends HTMLElement {
this[name] = value
return
}
const el = this.#getElement()
const el = this._getElement()
if (el) {
return el.setAttribute(name, value)
}
Expand All @@ -222,7 +222,7 @@ class DDGRuntimeChecks extends HTMLElement {
delete this[name]
return
}
const el = this.#getElement()
const el = this._getElement()
if (el) {
return el.removeAttribute(name)
}
Expand All @@ -231,7 +231,7 @@ class DDGRuntimeChecks extends HTMLElement {

addEventListener (...args) {
if (shouldFilterKey(this.#tagName, 'listener', args[0])) return
const el = this.#getElement()
const el = this._getElement()
if (el) {
return el.addEventListener(...args)
}
Expand All @@ -240,7 +240,7 @@ class DDGRuntimeChecks extends HTMLElement {

removeEventListener (...args) {
if (shouldFilterKey(this.#tagName, 'listener', args[0])) return
const el = this.#getElement()
const el = this._getElement()
if (el) {
return el.removeEventListener(...args)
}
Expand All @@ -263,15 +263,15 @@ class DDGRuntimeChecks extends HTMLElement {
}

remove () {
const el = this.#getElement()
const el = this._getElement()
if (el) {
return el.remove()
}
return super.remove()
}

removeChild (child) {
const el = this.#getElement()
const el = this._getElement()
if (el) {
return el.removeChild(child)
}
Expand Down