Skip to content

docs(youtube-player): update loading example to avoid loading API multiple times #20767

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

Merged
merged 1 commit into from
Oct 14, 2020

Conversation

crisbeto
Copy link
Member

Adds some extra logic to the asynchronous loading example that illustrates how to avoid adding the API multiple times.

…tiple times

Adds some extra logic to the asynchronous loading example that illustrates
how to avoid adding the API multiple times.
@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent docs This issue is related to documentation merge safe target: patch This PR is targeted for the next patch release labels Oct 11, 2020
@google-cla google-cla bot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Oct 11, 2020
@annieyw annieyw added the action: merge The PR is ready for merge by the caretaker label Oct 12, 2020
@annieyw annieyw merged commit cc310f9 into angular:master Oct 14, 2020
annieyw pushed a commit that referenced this pull request Oct 14, 2020
…tiple times (#20767)

Adds some extra logic to the asynchronous loading example that illustrates
how to avoid adding the API multiple times.

(cherry picked from commit cc310f9)
@mbtestfeed
Copy link

Hi @crisbeto . Thanks for doing this. I was planning to get to this PR, then work picked up a lot (still pretty busy but I had a chance to come see if anything had happened here!)

I'm slightly concerned that unless I'm missing something, this doesn't actually seem to fix #20644 or point the implementer in the right direction.
With this implementation it will stop this instance of the component from reloading the script. But if someone has multiple instances of the component on a page, or has this component in a modal that they open and close and re-open then the scope of apiLoaded won't be visible to the other instances of the component. Because of that confined scope we'll still be adding multiple instances of the script to the document body.

I think you're right in terms of cleaning up the example (my proposed solution definitely had a bit of code smell...) - but perhaps where we initiate the variable a comment of // ideally apiLoaded would be a get function that checks the document body for the script and returns a boolean or similar would be beneficial?

I dunno. Maybe as-is is enough. Would be curious to hear your thoughts.

@crisbeto
Copy link
Member Author

crisbeto commented Nov 2, 2020

@mbtestfeed the scope in which we have the apiLoaded variable is available to all instance of the YouTube player, even if they've been added at a later point.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Dec 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement docs This issue is related to documentation P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants