Git Product home page Git Product logo

Comments (3)

guybedford avatar guybedford commented on May 12, 2024 1

Is this effectively a Promise.all() or Promise.race()? Also, why? I'm a little confused by why they should run in parallel.

It's a Promise.all, the reason being that is the most performant design when we don't want to unnecessarily serialize to slow down imports. If two loaders both want to do fs / network / other async operations when a new import is initiated, there's no reason they need to block eachother.

In your example, you have if (context.topLevel), but topLevel is not in context currently or in your proposed additions. What does it mean? I presume top-level await, but that's what dynamic intends to identify, no?

Ahh thanks for spotting the issue in the example, that should be context.dynamic yes. I've gone back and fourth on the wording to get something clear. A top-level import is basically an import which will run the ECMA-262 top-level Evaluation function - https://tc39.es/ecma262/#sec-moduleevaluation. Not all modules go through a whole graph execution operation (eg most dependencies). topLevel is perhaps more descriptive than dynamic, but both likely need clarification. I have a better definition in the current readme update I'll add to the PR now.

I'm a little concerned by the pre prefixes: I already find globalPreload confusing (it's effectively a “setup” step). I think if we introduce this new hook, we should re-visit the globalPreload name (especially because it does not behave like the other hooks).

My preference would have been to just call it the import hook, but export function import() isn't supported in ECMA-262 unfortunately. I'm open to alternative names, eg beforeImport or importHook or prepareImport etc.

Yes, both globalPreload and preImport are effectively non-chainable hooks which can run without blocking other hooks. They fall under a different parallel hook model. In the loader documentation it could be worth eg explicitly documenting the "hook type" of each hook something like Hook Type: Sync Chained or Hook Type: Async Parallel, and there may also be other variants in future.

from loaders.

JakobJingleheimer avatar JakobJingleheimer commented on May 12, 2024

This is an interesting idea! I have a couple questions:

  • All preImport hooks for all loaders are run asynchronously in parallel,
    and block any further load operations (ie resolve and load) for the module graph
    being imported until they all complete successfully.

    Is this effectively a Promise.all() or Promise.race()? Also, why? I'm a little confused by why they should run in parallel.

  • In your example, you have if (context.topLevel), but topLevel is not in context currently or in your proposed additions. What does it mean? I presume top-level await, but that's what dynamic intends to identify, no?

I'm a little concerned by the pre prefixes: I already find globalPreload confusing (it's effectively a “setup” step). I think if we introduce this new hook, we should re-visit the globalPreload name (especially because it does not behave like the other hooks).

P.S. Sorry for the delayed reply; I'm only just seeing this now.

from loaders.

GeoffreyBooth avatar GeoffreyBooth commented on May 12, 2024

Closing in favor of #89

from loaders.

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.