You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given that chrome already shipped createShadowRoot and it's incompatible with the syntax we decided on at our April meeting, we need a new, possibly better name for the same. @rniwa, @hober, and @othermaciej and I briefly discussed this and came up with attachShadow.
It's easy to have removeShadow in the spec (and the implementation, I think).
The reason we don't have it is that I've never heard a strong request for that.
Since multiple shadow roots have been removed, I think it's okay to have removeShadow.
BTW, having attachShadow and removeShadow sound inconsistent. attach/detach sounds consistent, however, ShadowRoot can't live without a host element so far.
Do you have an interest to have a ShadowRoot without a shadow host?
My rough idea is:
varshadowHost=document.createElement('div');// shadowHost.shadowRoot == nullvarshadowRoot=document.createShadowRoot();// New API// shadowRoot.host == nullshadowHost.attachShadow(shadowRoot);// New API// shadowHost.shadowRoot == shadowRoot// shadowRoot.host == shadowHostvarsr=shadowHost.detachShadow();// New API// shadowRoot == sr// shadowHost.shadowRoot == null// sr.host == null
Is this better?
Note that this implies that ShadowRoot instance is no longer tightly associated with particular shadow host in it's lifecycle. We can re-use the same ShadowRoot instance as other shadow host's shadow tree. Attaching a ShadowRoot implies detaching it from the former shadow host, if it's already attached.
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:
consts=newShadowRoot({ mode });// s is not yet associated to a hosts.host=someHost;// now it iss.host=otherHost;// detach from someHost, attach to otherHosts.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
Element.prototype.attachShadow=function(shadowInitDict){// Web IDL argument/this validation hereconsts=newShadowRoot(shadowInitDict);s.host=this;returns;};
and a putative detachShadow is
Element.prototype.detachShadow=function(shadowInitDict){// Web IDL this validation hereconsts=this@[[shadowRoot]];if(!s){thrownewDOMException("blahblahblah","pickatype");}s.host=null;returns;};
In case it wasn't clear, that can all be v2 stuff, retrofitted on top of a naive attachShadow definition. Although it is simple enough and nice enough that I am not sure why it wouldn't be v1. I am obviously biased :)
Activity
annevk commentedon Jul 2, 2015
Will we get
removeShadowthis time around as well?hayatoito commentedon Jul 2, 2015
I'm okay to have
removeShadow. However, can we explain a use case for that?hayatoito commentedon Jul 2, 2015
It's easy to have
removeShadowin the spec (and the implementation, I think).The reason we don't have it is that I've never heard a strong request for that.
Since multiple shadow roots have been removed, I think it's okay to have
removeShadow.BTW, having
attachShadowandremoveShadowsound inconsistent.attach/detachsounds consistent, however, ShadowRoot can't live without a host element so far.Do you have an interest to have a ShadowRoot without a shadow host?
My rough idea is:
Is this better?
Note that this implies that ShadowRoot instance is no longer tightly associated with particular shadow host in it's lifecycle. We can re-use the same ShadowRoot instance as other shadow host's shadow tree. Attaching a ShadowRoot implies detaching it from the former shadow host, if it's already attached.
dglazkov commentedon Jul 2, 2015
Can we move
removeShadowto v2?annevk commentedon Jul 2, 2015
Yeah, my bad for raising it here. I do like @hayatoito's idea of reusing
ShadowRootinstances, and giving them a constructor.domenic commentedon Jul 3, 2015
Constructors, hmm. Good idea.
As far as I can tell all the essential data about a shadow root is:
If we say that you can attach and detach shadow roots, then essentially we are saying that the host is mutable. Thus:
We then say that
attachShadowis defined asand a putative
detachShadowisdomenic commentedon Jul 3, 2015
In case it wasn't clear, that can all be v2 stuff, retrofitted on top of a naive
attachShadowdefinition. Although it is simple enough and nice enough that I am not sure why it wouldn't be v1. I am obviously biased :)annevk commentedon Jul 3, 2015
Would also be kind of cool if a shadow root could remain attached across multiple hosts. We'd be getting pretty close to decorators then.
[Fix WICG#129, WICG#289] Rename createShadowRoot to attachShadow.
[Fix WICG#129, WICG#289] Rename createShadowRoot to attachShadow.