Re: [webcomponents]: Of weird script elements and Benadryl

On Fri, Apr 12, 2013 at 3:30 PM, Dimitri Glazkov <>wrote:

> ... or "How the heck do we initialize custom elements in declarative
> syntax?"
> There were good questions raised about the nature of <script> element
> in the "platonic form" thread. Consider this syntax:
> <element name="foo-bar">
>     <script> ...</script>
>     <template> ... </template>
> </element>
> The way <element> should work is like this:
> a) when </element> is seen
> b) generate a constructor for this element

Based on what? Is this more magic? What if a constructor is provided?

Here are a few use case, followed by a proposed set of semantics:

Given the following custom element:

  <element name="foo-bar">
      class FooBar {}

The braces are used to illustrate that the script tag is optional, so it
might also look like:

  <element name="foo-bar">

  <!-- elsewhere in the document -->
    class FooBar {}

  (in a remote src file)
  class FooBar {}

  (in a module)
  module CustomElements {
    export class FooBar {}

  (that's later imported)
  import { FooBar } from "CustomElements";

(None of the following is precise, just a basic idea that works with every
example I've given above)

Script tags inside <element> are treated the same way as any script tag in
an HTML document would be treated.

[[ConvertName]] is an imaginary operation the does the following:
  Let _converted_ be the result of
    1. replacing the first character of argument _val_ with same character
converted to ASCII uppercase
    2. replacing each U+002D (HYPHEN-MINUS character '-') that is followed
by a lowercase ASCII letter, by removing the U+002D and converting the
lowercase letter that followed with the same uppercase ASCII character.
  Return _converted_.

For each <element>
  Parse <template> (I don't know what happens here, so just play along)
  Let _val_ be the value of the **name** attribute of <element>
  Let _name_ be the result of calling [[ConvertName]] with the argument
  Let _ctor_ be the result of calling Get([[Global]], _name_)
  If _ctor_ is undefined
    - Create a new class whose Identifier is _name_ which extends from
      (This is just an assumption, replace with whatever makes the most
  Call document.register with arguments _val_ and _ctor_

> b) run document.register
> c) run initialization code
>  As I see it, the problem is twofold:
> 1) The <script> element timing is weird. Since <script> is
> initialization code, it has to run after the </element> is seen. This
> is already contrary to a typical <script> element expectations.
> 2) The <script> element needs a way to refer to the custom element
> prototype it is initializing. Enclosing it in a function and calling
> it with <element> as |this| seemed like a simplest thing to do, but
> Rick and John had allergic reactions and had to be hospitalized.

Please don't trivialize valid concerns—it wasn't just John and I, Erik and
Allen echo'ed the same.

> So far, I haven't seen any other workable alternatives. TC39 peeps and
> others, help me find them.

see above.

> :DG<


Received on Friday, 12 April 2013 20:26:49 UTC