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

Prevent loading the API library until the element is attached #328

Open
platosha opened this issue Sep 7, 2016 · 2 comments
Open

Prevent loading the API library until the element is attached #328

platosha opened this issue Sep 7, 2016 · 2 comments

Comments

@platosha
Copy link

platosha commented Sep 7, 2016

Currently, the google-map element loads the API library just after the element is created. This creates issues if a temporary instance is created, which is not going to be attached.

Consider the following case:

/* First, create a temporary instance, for example,
to extract a prototype for some analysis purpose */
var proto = Object.getPrototypeOf(document.createElement('google-map'));

/* Later, another instance of map is created and used normally */
var mapElement = document.createElement('google-map');
mapElement.apiKey = '...';
document.body.appendChild(mapElement);

Expected outcome: the API library is loaded once only after the element is attached.

Actual outcome: the API library is loaded multiple times.

Solution idea: postpone loading the API library after the element is attached by wrapping the <google-maps-api> tag with <template is="dom-if" if="isAttached">...</template>

Note that debouncing the API url computation, as proposed in GoogleWebComponents/google-apis#77, is not a complete solution for this issue. For the use case above, it will make the second instance to load the API library with the key provided synchronously after the element creation, while the first instance still loads the API without a key.

@hossameldeen
Copy link

hossameldeen commented Dec 24, 2016

I'm facing a similar problem and trying to understand google-map's current behaviour. Seems to me that I can't use createElement with it at all, even if I'm creating only one element and attaching it to the dom directly.

For example, even this code alone doesn't work with me:

var mapElement = document.createElement('google-map');
mapElement.apiKey = '...';
document.body.appendChild(mapElement);

It first throws a warning of no-api-keys, then throws an error of loading the API multiple times.

So, my question, if anyone could help: I can't use createElement with google-map at all, can I?

Thanks!

@mlabarre
Copy link

+1

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

No branches or pull requests

3 participants