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

feat: monitoring attribute change

parent e509e80c
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
import {Pathfinder} from '../../data/pathfinder.mjs'; import {Pathfinder} from '../../data/pathfinder.mjs';
import {isFunction} from '../../types/is.mjs'; import {isFunction} from '../../types/is.mjs';
import {attributeObserverSymbol} from "../customelement.mjs";
export {initOptionsFromAttributes}; export {initOptionsFromAttributes};
...@@ -74,6 +75,30 @@ function initOptionsFromAttributes(element, options, mapping = {}, prefix = 'dat ...@@ -74,6 +75,30 @@ function initOptionsFromAttributes(element, options, mapping = {}, prefix = 'dat
} }
finder.setVia(optionName, value); finder.setVia(optionName, value);
// if element has an attribute observer, then register the attribute observer
if (element?.[attributeObserverSymbol]) {
element[attributeObserverSymbol][name] = (newValue, oldValue) => {
if (newValue === oldValue) return;
let changedValue = newValue;
if (typeOfOptionValue === 'boolean') {
changedValue = changedValue === 'true';
} else if (typeOfOptionValue === 'number') {
changedValue = Number(changedValue);
} else if (typeOfOptionValue === 'string') {
changedValue = String(changedValue);
} else if (typeOfOptionValue === 'object') {
changedValue = JSON.parse(changedValue);
}
finder.setVia(optionName, changedValue);
}
}
} }
}) })
......
import {expect} from "chai" import {expect} from "chai"
import {initOptionsFromAttributes} from "../../../../..//application/source/dom/util/init-options-from-attributes.mjs";
import {initJSDOM} from "../../../util/jsdom.mjs"; import {initJSDOM} from "../../../util/jsdom.mjs";
describe('initOptionsFromAttributes', () => { describe('initOptionsFromAttributes', () => {
let element; let element;
let options; let options;
let initOptionsFromAttributes;
before(async function () { before( function (done) {
await initJSDOM(); initJSDOM().then(() => {
import("../../../../..//application/source/dom/util/init-options-from-attributes.mjs").then((m) => {
initOptionsFromAttributes = m['initOptionsFromAttributes'];
done();
}) })
})
});
beforeEach(() => { beforeEach(() => {
options = {url: "", key: {subkey: "", caseSensitive: true}}; options = {url: "", key: {subkey: "", caseSensitive: true}};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment