Re: [w3c/webcomponents] Scoped Custom Element Registries (#716)

I'd like to ask, what is the desired approach of providing definitions of scoped custom elements?
In the example above I can see it's done imperatively by someone who attaches the shadow root. That is not necessarily the same person or entity who created the shadow tree.

I have a number of use cases where shadow root is created, therefore scoped custom elements registry could be used, not for custom elements. Even for custom elements, it does not have to be exactly the same for every instance. In those cases, shadow dom is created by a separate entity and just employed by the host.
 
I'd like to ask about a more declarative approach and defining elements closer to the markup that uses them, like:

```html
<template is="declarative-shadow-root"> to be stamped in different places.
  <link rel="import" href="/path/to/my-element/definition.html">
  or
  <script src="/path/to/my-element/definition.js"></script>
  or
  <script type="module" src="/path/to/my-element/definition.html"></script>
  or
  <script type="module">
    import {MyElement} from '/path/to/my-element/definition.js';
    import.meta.scriptElement.getRootNode().customElements.define('my-element',MyElement);
  </script>

   <p>Shadow dom that's encapsulated, independent, and works exactly the same anywhere it's attached</p>
   <my-element>scoped custom element, working in a scoped tree</my-element>  
</template>
```
The person who creates the markup for shadow dom is the one who knows best what elements need to be used.

I believe, above approach would be intuitive, and should play well with  [declarative Shadow DOM](https://github.com/whatwg/dom/issues/510).

However, given the HTML Imports are dead, classic `<script>`s have no access to `currentScript, currentRoot`, the only chance to achieve that is to give HTML Modules an access to current root https://github.com/w3c/webcomponents/issues/645, https://github.com/whatwg/html/issues/1013

-- 
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/716#issuecomment-367969217

Received on Friday, 23 February 2018 10:21:12 UTC