Polymer works async-ly - nice!

65 views
Skip to first unread message

ihab...@gmail.com

unread,
Aug 19, 2015, 4:19:22 PM8/19/15
to polym...@googlegroups.com
I just realized that the Polymer(...) declaration in a custom element can be asynchronous. In other words, the following works precisely as expected:

<dom-module id="foo">
  ...
</dom-module>
<script>
  window.setTimeout(function() {
    Polymer({
      is: "foo",
      ...
    });
  }, 5000);
</script>

All the foo elements are invisible until 5 seconds later, when they pop into place! This means I could enclose it in -- say -- a RequireJS module. Very nice work!

Ihab

--
Ihab A.B. Awad, Palo Alto, CA

Eric Bidelman

unread,
Aug 19, 2015, 5:44:04 PM8/19/15
to ihab...@gmail.com, polym...@googlegroups.com
You've stumbled onto the awesome sauce that is custom element upgrades :)


Polymer() is simply a convenience + features wrapper for document.registerElement(). You can have <your-element>
declared on the page, but until it's registered, it won't have of any of it's special features minted or shady/shadow dom created.

Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/CAG7xX7oDPjqmCKEg1vaoD%3D-xctRGP2zmXZN03J6LY9W5wAf0vQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

ihab...@gmail.com

unread,
Aug 19, 2015, 5:45:46 PM8/19/15
to Eric Bidelman, polym...@googlegroups.com
Haha -- thanks, good to know!

Pieter-Jan Vandormael

unread,
Aug 20, 2015, 5:01:25 PM8/20/15
to Polymer, ebi...@gmail.com
I believe you can also add a "unresolved" attribute and remove it 5 minutes later. Similar trick. There must be other ways too.

Op woensdag 19 augustus 2015 23:45:46 UTC+2 schreef Ihab Awad:

Michael Giuffrida

unread,
Aug 20, 2015, 6:06:33 PM8/20/15
to Eric Bidelman, ihab...@gmail.com, polymer-dev
This also explains why having Polymer({}) calls in JavaScript doesn't work as expected if the JavaScript is deferred, and you have other Polymer({}) calls in sync scripts (or HTML).


On Wed, Aug 19, 2015 at 2:43 PM, Eric Bidelman <ebi...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages