[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 #8 from Daniel Buchner <danieljb2@gmail.com> ---
(In reply to comment #7)
> (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.

I thought this was the case - it seems Google's Custom Elements polyfill (both
stable and master) never upgrades in-source elements when document.register()
is used anywhere other than an imported HTML file. I'll file a bug for Scott
and team on GitHub.

> > 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? :)

Yeah, this is a good summary of the use-case. It would be a factor if a
developer wanted to act on a type of element when it becomes ready and they
either don't control the definition/execution of it, or don't know when it will
be imported/registered.

Technically, the difficulty I was facing was due to the Google polyfill bug,
but I believe the scenario posed above remains a valid use-case - do you agree?

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

Received on Wednesday, 22 May 2013 21:41:08 UTC