Skip to content
Snippets Groups Projects
Verified Commit 1cdf3809 authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

feat: attribure observer

parent 49ed6f78
No related branches found
No related tags found
No related merge requests found
......@@ -203,6 +203,7 @@ class CustomElement extends HTMLElement {
this[internalSymbol] = new ProxyObserver({
options: initOptionsFromAttributes(this, extend({}, this.defaults)),
});
initAttributeChangeMutationObserver.call(this);
initOptionObserver.call(this);
this[initMethodSymbol]();
}
......@@ -217,7 +218,9 @@ class CustomElement extends HTMLElement {
}
/**
* This method determines which attributes are to be monitored by `attributeChangedCallback()`.
* This method determines which attributes are to be
* monitored by `attributeChangedCallback()`. Unfortunately, this method is static.
* Therefore, the `observedAttributes` property cannot be changed during runtime.
*
* @return {string[]}
* @since 1.15.0
......@@ -421,7 +424,8 @@ class CustomElement extends HTMLElement {
try {
value = new Pathfinder(this[internalSymbol].getRealSubject()["options"]).getVia(path);
} catch (e) {}
} catch (e) {
}
if (value === undefined) return defaultValue;
return value;
......@@ -491,7 +495,8 @@ class CustomElement extends HTMLElement {
try {
initShadowRoot.call(self);
elements = self.shadowRoot.childNodes;
} catch (e) {}
} catch (e) {
}
try {
initCSSStylesheet.call(this);
......@@ -542,7 +547,8 @@ class CustomElement extends HTMLElement {
* @return {void}
* @since 1.7.0
*/
disconnectedCallback() {}
disconnectedCallback() {
}
/**
* The custom element has been moved into a new document (e.g. someone called document.adoptNode(el)).
......@@ -550,7 +556,8 @@ class CustomElement extends HTMLElement {
* @return {void}
* @since 1.7.0
*/
adoptedCallback() {}
adoptedCallback() {
}
/**
* Called when an observed attribute has been added, removed, updated, or replaced. Also called for initial
......@@ -595,6 +602,32 @@ class CustomElement extends HTMLElement {
}
}
/**
* This method is called when the element is first created.
*
* @private
* @this CustomElement
*/
function initAttributeChangeMutationObserver() {
const self = this;
if (self[attributeObserverSymbol] === undefined) {
self[attributeObserverSymbol] = {};
}
new MutationObserver(function (mutations) {
for (const mutation of mutations) {
if (mutation.type === "attributes") {
self.attributeChangedCallback(mutation.attributeName, mutation.oldValue, mutation.target.getAttribute(mutation.attributeName));
}
}
}).observe(self, {
attributes: true,
attributeOldValue: true,
attributeFilter: Object.keys(self[attributeObserverSymbol]),
});
}
/**
* @this CustomElement
* @private
......@@ -787,7 +820,8 @@ function parseOptionsJSON(data) {
try {
let dataUrl = parseDataURL(data);
data = dataUrl.content;
} catch (e) {}
} catch (e) {
}
try {
obj = JSON.parse(data);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment