Skip to content

Commit

Permalink
feat(base): implement late validation (#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladitasev authored Jun 10, 2019
1 parent 1709455 commit c452d60
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
6 changes: 3 additions & 3 deletions packages/base/src/UI5Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class UI5Element extends HTMLElement {
}

static get observedAttributes() {
const observedProps = this.getMetadata().getObservedProps();
const observedProps = this.getMetadata().getPublicPropsList();
return observedProps.map(camelToKebabCase);
}

Expand Down Expand Up @@ -268,8 +268,8 @@ class UI5Element extends HTMLElement {
}

_upgradeAllProperties() {
const observedProps = this.constructor.getMetadata().getObservedProps();
observedProps.forEach(this._upgradeProperty.bind(this));
const allProps = this.constructor.getMetadata().getPropsList();
allProps.forEach(this._upgradeProperty.bind(this));
}

static define() {
Expand Down
22 changes: 16 additions & 6 deletions packages/base/src/UI5ElementMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ class UI5ElementMetadata {
return this.metadata.defaultSlot || "content";
}

getObservedProps() {
const properties = this.getProperties();
const allProps = Object.keys(properties);
const observedProps = allProps.filter(UI5ElementMetadata.isPublicProperty);
return observedProps;
getPropsList() {
return Object.keys(this.getProperties());
}

getPublicPropsList() {
return this.getPropsList().filter(UI5ElementMetadata.isPublicProperty);
}

getSlots() {
Expand Down Expand Up @@ -99,7 +100,16 @@ const validateSingleSlot = (value, slotData) => {
const slottedNodes = getSlottedNodes(value);
slottedNodes.forEach(el => {
if (!(el instanceof propertyType)) {
throw new Error(`${el} is not of type ${propertyType}`);
const isHTMLElement = el instanceof HTMLElement;
const tagName = isHTMLElement && el.tagName.toLowerCase();
const isCustomElement = isHTMLElement && tagName.includes("-");
if (isCustomElement) {
window.customElements.whenDefined(tagName).then(() => {
if (!(el instanceof propertyType)) {
throw new Error(`${el} is not of type ${propertyType}`);
}
});
}
}
});

Expand Down
13 changes: 0 additions & 13 deletions packages/main/src/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import ListItemBase from "./ListItemBase.js";
import ListMode from "./types/ListMode.js";
import ListSeparators from "./types/ListSeparators.js";
import ListItemType from "./types/ListItemType.js";
import StandardListItem from "./StandardListItem.js";
import CustomListItem from "./CustomListItem.js";
import GroupHeaderListItem from "./GroupHeaderListItem.js";
// Template
import ListRenderer from "./build/compiled/ListRenderer.lit.js";

Expand Down Expand Up @@ -589,16 +586,6 @@ class List extends UI5Element {
},
};
}

static async define(...params) {
await Promise.all([
StandardListItem.define(),
CustomListItem.define(),
GroupHeaderListItem.define(),
]);

super.define(...params);
}
}

Bootstrap.boot().then(_ => {
Expand Down

0 comments on commit c452d60

Please sign in to comment.