From 813b98e3306a77a7abb427e59de49e8b2db64381 Mon Sep 17 00:00:00 2001 From: Dmitry Sharabin Date: Sun, 23 Jun 2024 12:52:51 +0200 Subject: [PATCH] Fix the issue with plugins not loaded in time (#162) * Return promises to be resolved, not the plugin objects (with all other promises and metadata) itself * Don't await `slideshowCreated` It resolves _after_ this plugin should be loaded. --- plugins/live-demo/plugin.js | 22 +++++++++++----------- src/plugins.js | 7 ++----- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/plugins/live-demo/plugin.js b/plugins/live-demo/plugin.js index 7387407..ad101a6 100644 --- a/plugins/live-demo/plugin.js +++ b/plugins/live-demo/plugin.js @@ -123,18 +123,18 @@ document.addEventListener("slidechange", evt => { } }); -await Inspire.slideshowCreated; - -if (Inspire.currentSlide?.classList.contains("demo")){ - LiveDemo.init(Inspire.currentSlide); -} +Inspire.slideshowCreated.then(() => { + if (Inspire.currentSlide?.classList.contains("demo")){ + LiveDemo.init(Inspire.currentSlide); + } -// var io = new IntersectionObserver(entries => { -// entries.forEach(entry => LiveDemo.init(entry.target)); -// }); + // var io = new IntersectionObserver(entries => { + // entries.forEach(entry => LiveDemo.init(entry.target)); + // }); -// $$(".demo.slide").forEach(demo => { -// io.observe(demo); -// }); + // $$(".demo.slide").forEach(demo => { + // io.observe(demo); + // }); +}); export {LiveDemo}; \ No newline at end of file diff --git a/src/plugins.js b/src/plugins.js index 8011d7b..378d758 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -54,11 +54,8 @@ export function loadAll (plugins = registry) { if (doLoad && !dontLoad) { let plugin = load(id, def); // plugin.loaded.then(_ => ret.push(plugin)); - plugin.loaded.then( - plugin => ret.push(plugin), - - ).catch(e => console.error(`Plugin ${id} error:`, e)) - ; + plugin.loaded.catch(e => console.error(`Plugin ${id} error:`, e)); + ret.push(plugin.loaded); } }