Skip to content

Commit

Permalink
Fix the issue with plugins not loaded in time (#162)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
DmitrySharabin authored Jun 23, 2024
1 parent f50e735 commit 813b98e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
22 changes: 11 additions & 11 deletions plugins/live-demo/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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};
7 changes: 2 additions & 5 deletions src/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 813b98e

Please sign in to comment.