Skip to content

Commit

Permalink
🎛️: prevent multiple instances of lite-youtube-embed from executing
Browse files Browse the repository at this point in the history
Co-authored-by: Robin Schreiber <[email protected]>
  • Loading branch information
linusha and merryman committed Jul 24, 2024
1 parent fbd8cf2 commit 5da4852
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lively.components/youtube-morph.cp.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { component, ViewModel, HTMLMorph } from 'lively.morphic';
import { pt } from 'lively.graphics/geometry-2d.js';
import { fun } from 'lively.lang';

class YouTubeEmbedViewModel extends ViewModel {
static get properties () {
Expand All @@ -10,8 +11,12 @@ class YouTubeEmbedViewModel extends ViewModel {
}

async viewDidLoad () {
// Browsers do not like us importing this in more than once place...
window.liteYouTubeEmbed ? null : (window.liteYouTubeEmbed = await System.import('lite-youtube-embed'));
// Browsers do not like us importing this in more than once...
if (!window.liteYouTubeEmbed) {
await fun.guardNamed('import-lite-youtube-embed', async () => {
window.liteYoutubeEmbed = await System.import('lite-youtube-embed');
})();
}
this.view.html = `<lite-youtube videoid="${this.videoID}" width="100%" height="100%" style="max-width: ${this.maxWidth};"></lite-youtube>`;
}
}
Expand Down

0 comments on commit 5da4852

Please sign in to comment.