- From: Andrea Giammarchi <notifications@github.com>
- Date: Fri, 29 Sep 2017 13:49:53 -0700
- To: w3c/webcomponents <webcomponents@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Friday, 29 September 2017 20:50:14 UTC
> it would reject the promise instead of resolving it later when it gets upgraded.
just to be sure I understand ... considering the following code:
```js
customElements.define('be-fore', class extends HTMLElement {});
const tp = document.createElement('template');
tp.innerHTML = '<be-fore></be-fore><af-ter></af-ter>';
// are you saying this will resolve ...
customElements.whenDefined(tp.content.firstChild).then(console.log);
// ... but this will throw rught away ?
customElements.whenDefined(tp.content.lastChild).catch(console.error);
// since the element is defined after ?
customElements.define('af-ter', class extends HTMLElement {});
```
This is a caveat with CE that might work for me, but it's hard to explain together with the current `whenDefined` mechanism, where you ask for a CE not defined yet.
To solve this though, the following might work as well:
```js
function setDirectValue(node, value) {
customElements
.whenDefined(node.nodeName.toLowerCase())
.then(() => {
customElements.whenDefined(node)
.then(() => {
node.direct = value;
});
});
}
```
This works for me.
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/webcomponents/issues/671#issuecomment-333235697
Received on Friday, 29 September 2017 20:50:14 UTC