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

feat: Enhance CustomElement with validation and customization capabilities

Summary of changes
- Added validation for options in CustomElement constructor.
- Implemented a new mechanism to set customization values using a Map.
- Updated customization getter to return a new Map.

Changes
- In the constructor, validated if the options are correctly defined. This prevents potential issues down the line if the options are not an object.
- Introducing a Pathfinder that allows for setting deep customization values using a Map. This makes it easier to manipulate specific values without redefining the entire structure, preserving the original defaults.
- Updated the customization property getter to ensure it returns a Map instead of an object, thus aligning with the new customization mechanism.

These changes improve the robustness of the CustomElement, ensuring users have more flexibility while maintaining a safety net against misconfigurations.
parent 42b8fc06
No related branches found
No related tags found
No related merge requests found
......@@ -197,9 +197,22 @@ class CustomElement extends HTMLElement {
super();
this[attributeObserverSymbol] = {};
this[internalSymbol] = new ProxyObserver({
options: initOptionsFromAttributes(this, extend({}, this.defaults)),
const options = initOptionsFromAttributes(this, extend({}, this.defaults));
if (!isObject(options)) {
throw new Error(
`The options are not defined correctly in the ${this.getTag()} element.`,
);
}
if (this.customization instanceof Map) {
const pathfinder = new Pathfinder(options);
this.customization.forEach((value, key) => {
pathfinder.setVia(key, value);
});
}
this[internalSymbol] = new ProxyObserver({ options });
this[initMethodSymbol]();
initOptionObserver.call(this);
this[scriptHostElementSymbol] = [];
......@@ -249,6 +262,17 @@ class CustomElement extends HTMLElement {
return this;
}
/**
* The `customization` property allows overwriting the defaults.
* Unlike the defaults that expect an object, the customization is a Map.
* This also allows overwriting individual values in a deeper structure
* without having to redefine the entire structure and thus changing the defaults.
* @returns {Map}
*/
get customization() {
return new Map();
}
/**
* The `defaults` property defines the default values for a control. If you want to override these,
* you can use various methods, which are described in the documentation available at
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment