W3C home > Mailing lists > Public > public-webapps@w3.org > October to December 2012

[webcomponents]: Changing API from constructable ShadowRoot to factory-like

From: Dimitri Glazkov <dglazkov@google.com>
Date: Wed, 7 Nov 2012 10:36:25 -0800
Message-ID: <CADh5Ky3NeZ=skKmo9KCN6NE_kAO5E+1NHbrzv27KR3VYcsVDvw@mail.gmail.com>
To: public-webapps <public-webapps@w3.org>
Cc: Blake Kaplan <mrbkap@mozilla.com>, Jonas Sicking <sicking@mozilla.com>, Elliott Sprehn <esprehn@google.com>, Maciej Stachowiak <mjs@apple.com>, Boris Zbarsky <bzbarsky@mit.edu>

Throughout the year-long (whoa!) history of the Shadow DOM spec,
various people commented on how odd the constructable ShadowRoot
pattern was:

var root = new ShadowRoot(host); // both creates an instance *and*
makes an association between this instance and host.

People (I cc'd most of them) noted various quirks, from the
side-effectey constructor to relatively uncommon style of the API.

I once was of the strong opinion that having a nice, constructable
object has better ergonomics and would overcome the mentioned code

But... As we're discussing traversable shadows and the possibility of
having Element.shadowRoot, the idea of changing to a factory pattern
now looks more appealing:

var element = document.querySelector('div#foo');
alert(element.shadowRoot); // null
var root = element.addShadowRoot({ resetStyleInheritance: true });
alert(root === element.shadowRoot); // true
var root2 = element.addShadowRoot();
alert(root === element.shadowRoot); // false
alert(root2 === element.shadowRoot); // true

You gotta admit this looks very consistent and natural relative to how
DOM APIs work today.

We could still keep constructable object syntax as alternative method
or ditch it altogether and make calling constructor throw an

What do you think, folks? In the spirit of last night's events, let's vote:

1) element.addShadowRoot rocks! Let's make it the One True Way!
2) Keep ShadowRoot constructable! Factories stink!
3) Let's have both!
4) element.addShadowRoot, but ONLY if we have traversable shadow trees
5) Kodos.


P.S. I would like to retain the atomic quality of the operation:
instantiate+associate in one go. There's a whole forest of problems
awaits those who contemplate detached shadow roots.
Received on Wednesday, 7 November 2012 18:36:53 UTC

This archive was generated by hypermail 2.3.1 : Friday, 27 October 2017 07:26:50 UTC