- From: Joe Pea <notifications@github.com>
- Date: Mon, 31 Aug 2020 14:09:50 -0700
- To: w3c/webcomponents <webcomponents@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
Received on Monday, 31 August 2020 21:10:02 UTC
I thought I'd update the code examples from https://github.com/w3c/webcomponents/issues/871#issuecomment-604741570.
```js
class CustomHTMLElement extends HTMLElement {
#internals = this.attachInternals()
#shadow = this.#internals.shadowRoot ?? this.attachShadow({mode: 'closed'})
}
```
vs
```js
class CustomHTMLElement extends HTMLElement {
#existingShadow = this.attachShadow({returnExistingDeclarativeShadowRoot: true})
#shadow = this.#existingShadow ?? this.attachShadow({mode: 'closed'})
}
```
And if @rniwa you meant that a single call to `attachShadow` would create a new root with the given mode only if an existing one doesn't exist, then your original example simplifies to
```js
class CustomHTMLElement extends HTMLElement {
#shadow = this.attachShadow({mode: 'closed', returnExistingDeclarativeShadowRoot: true})
}
```
--
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/871#issuecomment-684041455
Received on Monday, 31 August 2020 21:10:02 UTC