Visitar URL original
docs(youtube-player): update loading example to avoid loading API multiple times by crisbeto · Pull Request #20767 · angular/components · GitHub
The Wayback Machine - https://web.archive.org/web/20260424094715/https://github.com/angular/components/pull/20767
Skip to content

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

Merged
annieyw merged 1 commit intoangular:masterfrom
crisbeto:20644/youtube-player-loading
Oct 14, 2020
Merged

docs(youtube-player): update loading example to avoid loading API multiple times#20767
annieyw merged 1 commit intoangular:masterfrom
crisbeto:20644/youtube-player-loading

Conversation

@crisbeto
Copy link
Copy Markdown
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
Copy Markdown

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
Copy Markdown
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
Copy Markdown

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