- From: Tomek Wytrębowicz <notifications@github.com>
- Date: Sat, 21 Oct 2017 14:30:40 -0700
- To: w3c/webcomponents <webcomponents@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <w3c/webcomponents/issues/674/338433769@github.com>
@trusktr I'd like to make sure I understand your need correctly. You would like to give the author a way to explicitly reject all promises for `whenDefined` given custom element? Like,
```js
customElements.define('any-thing', SomeElement);
// SomeElement logic:
for (const elm of Array.from(this.children)) {
if (elm.nodeName.includes('-')) {
customElements.whenDefined(elm.nodeName.toLowerCase()).then(() => {
if (elm instanceof OtherElement) {
// do something only if the child is an OtherElement
}
})
}
}
// once author knows that `an-element` definition will never come, for example because he/she deliberetly didn't import it
customElements.stopWaitingFor('an-element'); // resolves promise with rejection, letting callback to be collected.
```
or just for a given call? To reject a promise that this particular element will be upgraded.
```js
customElements.define('any-thing', SomeElement);
// SomeElement logic:
for (const elm of Array.from(this.children)) {
if (elm.nodeName.includes('-')) {
elm.whenUpgraded.then(() => {
if (elm instanceof OtherElement) {
// do something only if the child is an OtherElement
}
})
}
}
// once author knows that given element will never get upgraded to `an-element`,
rejectUpgradePromise(document.querySelector('any-thing an-element'), 'reason: nuked'); // something that rejects a promise for that instance
```
--
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/674#issuecomment-338433769
Received on Saturday, 21 October 2017 21:31:01 UTC