[Bug 20189] [Custom]: Provide an event that signals when all custom elements in static source are ready/upgraded

https://www.w3.org/Bugs/Public/show_bug.cgi?id=20189

--- Comment #7 from Dimitri Glazkov <dglazkov@chromium.org> ---
(In reply to comment #6)
> I don't see how we get out of offering an event, consider the following:
> 
> What happens when someone implements and registers their tag definition with
> purely imperative code via a <script> included in original source or any
> script piped in that is late-firing?  If I register an element with
> document.register within a script, am I to presume there is no event to let
> me know when that code has upgraded all the nodes in the document that match
> the definition? If so, this could be a significant landmine for developers.

The document.register is synchronous. In other words, anytime you register an
element imperatively, the nodes will be upgraded as soon as document.register
returns.

There is no timing difference between element registration and element upgrade.
They are an atomic operation from the spec perspective -- see steps of
https://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/custom/index.html#dfn-element-registration-algorithm.

> My suggestion would be to fire one 'CustomElementsUpgraded' event for each
> *type* of element declared (which would contain an 'elementName' property)
> when all elements of that type present in the DOM have been upgraded. This
> would allow developers to know when elements are OK to touch regardless of
> which declaration route they opt for, or how 'late' they register an element.

Is the purpose of such event to let consumers of a specific custom element to
observe when such custom element is registered?

For example, Bob wants to use <foo-bar>, and he wants to listen to an event
that tells him that <foo-bar> has loaded from some set of HTML imports. The
only place where I see this useful is if Bob has a script that runs _before_
imports (or calls to document.register):

<script>

document.addEventListener('register', functon(evt) {
    if (evt.localName == 'foo-bar') {
        // do stuff ...
    }
});

</script>
<link rel="import" href="some-component-library.html">
...

Did I get this right? :)

-- 
You are receiving this mail because:
You are the QA Contact for the bug.

Received on Wednesday, 22 May 2013 21:01:12 UTC