- From: Domenic Denicola <notifications@github.com>
- Date: Thu, 02 Jul 2015 18:09:56 -0700
- To: w3c/webcomponents <webcomponents@noreply.github.com>
- Message-ID: <w3c/webcomponents/issues/129/118205891@github.com>
Constructors, hmm. Good idea.
As far as I can tell all the essential data about a shadow root is:
- its host element
- its mode
If we say that you can attach and detach shadow roots, then essentially we are saying that the host is mutable. Thus:
```js
const s = new ShadowRoot({ mode });
// s is not yet associated to a host
s.host = someHost; // now it is
s.host = otherHost; // detach from someHost, attach to otherHost
s.host = null; // now it is not attached to any host
// Note: a side effect of `s.host = x` is setting `x@[[shadowRoot]]` to `s`.
// (`x@[[shadowRoot]] is notation for what the spec calls "x's shadow root")
```
We then say that `attachShadow` is defined as
```js
Element.prototype.attachShadow = function (shadowInitDict) {
// Web IDL argument/this validation here
const s = new ShadowRoot(shadowInitDict);
s.host = this;
return s;
};
```
and a putative `detachShadow` is
```js
Element.prototype.detachShadow = function (shadowInitDict) {
// Web IDL this validation here
const s = this@[[shadowRoot]];
if (!s) {
throw new DOMException("blahblahblah", "pickatype");
}
s.host = null;
return s;
};
```
---
Reply to this email directly or view it on GitHub:
https://github.com/w3c/webcomponents/issues/129#issuecomment-118205891
Received on Friday, 3 July 2015 01:10:25 UTC