Skip to content

Commit c452d60

Browse files
authored
feat(base): implement late validation (#522)
1 parent 1709455 commit c452d60

File tree

3 files changed

+19
-22
lines changed

3 files changed

+19
-22
lines changed

packages/base/src/UI5Element.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ class UI5Element extends HTMLElement {
217217
}
218218

219219
static get observedAttributes() {
220-
const observedProps = this.getMetadata().getObservedProps();
220+
const observedProps = this.getMetadata().getPublicPropsList();
221221
return observedProps.map(camelToKebabCase);
222222
}
223223

@@ -268,8 +268,8 @@ class UI5Element extends HTMLElement {
268268
}
269269

270270
_upgradeAllProperties() {
271-
const observedProps = this.constructor.getMetadata().getObservedProps();
272-
observedProps.forEach(this._upgradeProperty.bind(this));
271+
const allProps = this.constructor.getMetadata().getPropsList();
272+
allProps.forEach(this._upgradeProperty.bind(this));
273273
}
274274

275275
static define() {

packages/base/src/UI5ElementMetadata.js

+16-6
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ class UI5ElementMetadata {
1717
return this.metadata.defaultSlot || "content";
1818
}
1919

20-
getObservedProps() {
21-
const properties = this.getProperties();
22-
const allProps = Object.keys(properties);
23-
const observedProps = allProps.filter(UI5ElementMetadata.isPublicProperty);
24-
return observedProps;
20+
getPropsList() {
21+
return Object.keys(this.getProperties());
22+
}
23+
24+
getPublicPropsList() {
25+
return this.getPropsList().filter(UI5ElementMetadata.isPublicProperty);
2526
}
2627

2728
getSlots() {
@@ -99,7 +100,16 @@ const validateSingleSlot = (value, slotData) => {
99100
const slottedNodes = getSlottedNodes(value);
100101
slottedNodes.forEach(el => {
101102
if (!(el instanceof propertyType)) {
102-
throw new Error(`${el} is not of type ${propertyType}`);
103+
const isHTMLElement = el instanceof HTMLElement;
104+
const tagName = isHTMLElement && el.tagName.toLowerCase();
105+
const isCustomElement = isHTMLElement && tagName.includes("-");
106+
if (isCustomElement) {
107+
window.customElements.whenDefined(tagName).then(() => {
108+
if (!(el instanceof propertyType)) {
109+
throw new Error(`${el} is not of type ${propertyType}`);
110+
}
111+
});
112+
}
103113
}
104114
});
105115

packages/main/src/List.js

-13
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ import ListItemBase from "./ListItemBase.js";
99
import ListMode from "./types/ListMode.js";
1010
import ListSeparators from "./types/ListSeparators.js";
1111
import ListItemType from "./types/ListItemType.js";
12-
import StandardListItem from "./StandardListItem.js";
13-
import CustomListItem from "./CustomListItem.js";
14-
import GroupHeaderListItem from "./GroupHeaderListItem.js";
1512
// Template
1613
import ListRenderer from "./build/compiled/ListRenderer.lit.js";
1714

@@ -589,16 +586,6 @@ class List extends UI5Element {
589586
},
590587
};
591588
}
592-
593-
static async define(...params) {
594-
await Promise.all([
595-
StandardListItem.define(),
596-
CustomListItem.define(),
597-
GroupHeaderListItem.define(),
598-
]);
599-
600-
super.define(...params);
601-
}
602589
}
603590

604591
Bootstrap.boot().then(_ => {

0 commit comments

Comments
 (0)