Re: [webcomponents]: Platonic form of custom elements declarative syntax

On Wed, Apr 10, 2013 at 8:22 PM, Daniel Buchner <daniel@mozilla.com> wrote:

> It seems there are a few things we should decide on that will affect our
> API decision:
>
>    1. Are we comfortable with having <script> elements scoped to
>    templates or elements they are associated with - this means adjusting the
>    value of 'this' or 'self', etc.
>
> Everyone's answer to this should be "no"; changing the expected value of
the top level "this", in some magical way, simply won't work. John's
suggestion for an associated class (or constructor function, whichever is
preferred) is the right track.

Building on John's example:



<element tagname="foo">
  <template>
    <shadowroot>
      <div>The shadow knows...</div>
    </shadowroot>
  </template>
  <script>
    // This way, I can extend from other classes if I want to
    class Foo extends EventTarget() {
      constructor() {
        super();

        // "*" just means "listen to all the events". I made it up, use
your imaginations
        this.addEventListener("*", event => {
          switch (event.type) {
            case "bind":
              ...
              break;

            case "unbind":
              ...
              break;
          }
        });
      }
      static @@create() {
        ... this is the @@create that Erik has mentioned previously.
      }
    }
  </script>
</element>




Rick



>    1. How do we want to associate <template> elements with custom tags?
>    Which direction is the association made, template tells the element "I'm
>    coming over for dinner <element>, better set a place!", or element says
>    "Hey there template, you're looking pretty cool, I'd like to use you." - I
>    prefer the latter, as it provides for many more use-cases (don't think this
>    is opinion) via more sane way that developers will expect (this may be
>    opinion).
>    2. Do we use events for the <template> actions (bind, unbind, etc), or
>    script tags with special attributes that dictate when a code block (or
>    linked resource) is run? (would the latter mean we need another special
>    attribute like 'runwhenunbound'?)
>
> *As usual, let me know if I have it wrong anywhere :)*
>
> Once we answer the open items above, I believe the optimal implementation
> will be easier to recognize.
>
>
>  On Wed, Apr 10, 2013 at 3:42 PM, John J Barton <
> johnjbarton@johnjbarton.com> wrote:
>
>>
>>
>>
>> On Wed, Apr 10, 2013 at 3:30 PM, Daniel Buchner <daniel@mozilla.com>wrote:
>>
>>> @John - in my opinion, <template bindtotagname="my-yay"> is the wrong
>>> direction. You should be declaring which *template* an *element* uses, not
>>> which element a template captures. Having templates latch onto element
>>> types from afar breaks the one-to-many case, prevents sane swapping of
>>> templates on a specific element node, and many other oddities.
>>> Alternatively, <element template="id-of-some-template"> is more flexible
>>> and the right 'direction' for such an association that suffers none of
>>> those issues, at least in my opinion. Feel free to disagree or set me
>>> straight if anything I said is not accurate :)
>>>
>>
>> I don't have any opinion on this aspect, sorry. I was only offering a
>> modernization of an old and not-popular-among-purists way of connecting
>> scripts and elements.
>>  jjb
>>
>
>

Received on Thursday, 11 April 2013 01:39:23 UTC