Giter VIP home page Giter VIP logo

Comments (2)

DmitrySharabin avatar DmitrySharabin commented on July 27, 2024

Another thing I noticed is that here

await Promise.allSettled(this.dependencies);
is expected that this.dependencies is an iterable of promises. However, even though this.dependencies is an iterable (an array), its elements are not promisesโ€”they are objects whose properties are promises:
let plugin = loaded[id] = {};
plugin.loading = pluginURL;
plugin.loadedJS = import(pluginURL).then(module => plugin.module = module);
plugin.loaded = plugin.loadedJS.then(module => {
if (!noCSS && module.hasCSS) {
let pluginCSS = new URL(`${path}/${id}/plugin.css`, import.meta.url);
plugin.loading = pluginCSS;
let link = util.create.in(document.head, `<link rel="stylesheet" href="${pluginCSS}">`);
return new Promise((res, rej) => {
link.onload = e => res(module);
link.onerror = rej;
});
}
return module;
});
// Resolves to the JS module, but only after CSS has also loaded
plugin.module = plugin.loaded;
plugin.done = plugin.loaded.finally(_ => {
plugin.loading = "";
});
return plugin;

Does Promise.allSettled() work in this case?

from inspire.js.

DmitrySharabin avatar DmitrySharabin commented on July 27, 2024

If we fix the code so that this.dependencies will be an array of promises, the code execution will freeze on this lineโ€”the promise corresponding to the live-demo plugin will never be resolved because on this line:

await Inspire.slideshowCreated;

The plugin awaits slideshowCreated to be resolved. However, it happens in init() which is called in setup()

this.init();

after all the plugins should be loaded (and the corresponding promises should be resolved):

This is the line where the slideshowCreated resolves:

_.slideshowCreated.resolve();

I submitted a PR with a possible fix: #162

@LeaVerou, could you please take a look?

from inspire.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.