Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reference to HTMLLinkElement in Polymer.import callback #1127

Closed
tomalec opened this issue Jan 27, 2015 · 2 comments
Closed

Reference to HTMLLinkElement in Polymer.import callback #1127

tomalec opened this issue Jan 27, 2015 · 2 comments

Comments

@tomalec
Copy link
Contributor

tomalec commented Jan 27, 2015

I'm trying to use Polymer.import helper to dynamically load some documents with Polymer Elements nested deeper inside. With native HTMLLinkElement#onload I could easyli access imported content to use it:

link.onload =  function(){
  // Insert template into DOM.
  var template = this.import.querySelector("template");

live example here
And it works like charm, except the problem with

Attributes on my-element were data bound prior to Polymer upgrading the element. This may result in incorrect binding types.

As onload may be called before Polymer upgrades the polymer elements. So I need either to hack it with Polymer's internal queue or at least with Polymer.whenReady like here or finally use Polymer.import which seems nice and clean.
However it does not give a reference to imported document neither with this nor via arguments.
So I need to write every time:

Polymer.import(["/my/path/here"], function(){
  var link = document.querySelector('link[href="/my/path/here"]');
  var template = link.import.querySelector("template");

live
What doesn't look that nice, and may hit the performance.

I suggest adding array of corresponding HTMLLinkElements as callback argument:

Polymer.import(["/my/path/here"], function(links){
  var template = links[0].import.querySelector("template");

So Polymer.import could be used as and alternative to native .onload.

@ebidel
Copy link
Contributor

ebidel commented Feb 7, 2015

+1. In a current project, I've also been using document.querySelector to get back the import that was added but Polymer.import should just pass this info in the callback.

@sorvell @sjmiles is this something we can add?

@tomalec
Copy link
Contributor Author

tomalec commented Feb 11, 2015

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants