You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Loving the proposal so far, however, I disagree that this cannot be useful for bundling, despite all modules defined as module blocks being anonymous and unable to directly reference each other.
Please consider the following pattern:
// Define modules relying on each otherconstmodule1=module{exportfunctionadd(a,b){returna+b}}constmodule2=module{constimported={// Prevent too eager consumption of imported valuesgetadd(){thrownewError('"add" has not been imported yet')},}exportfunctionsetImports(importedValues){Object.defineProperties(imported,importedValues)}exportfunctionsum(...numbers){returnnumbers.reduce((sum,value)=>imported.add(sum,value),0)}}// Initialize modulesconst[module1Exports,module2Exports]=awaitPromise.all([import(module1),import(module2)])// Link modulesmodule2Exports.setImports({add: {get(){returnmodule1Exports.add}}})// Use linked modulesassert(module2Exports.sum(1,2,3,4,5)===15)
Admissibly, this pattern would require the bundler to move any import-dependent top-level business logic to an exported function (let's call it init), which would be invoked during the linking stage once the init function's dependencies have been provided. Not necessarily all imports of the module need to be provided at that point, the rest can wait for the init function to complete and possibly update the exported values. (Or just flatten the bundle to work around this.)
This pattern allows for lazily referenced circular dependencies as well.
Thus I do not think that using JavaScript Module Fragments would be required, although those would do the linking stage for you and thus be a lot easier to use than hand-writing this.
The text was updated successfully, but these errors were encountered:
Loving the proposal so far, however, I disagree that this cannot be useful for bundling, despite all modules defined as module blocks being anonymous and unable to directly reference each other.
Please consider the following pattern:
Admissibly, this pattern would require the bundler to move any import-dependent top-level business logic to an exported function (let's call it
init
), which would be invoked during the linking stage once theinit
function's dependencies have been provided. Not necessarily all imports of the module need to be provided at that point, the rest can wait for theinit
function to complete and possibly update the exported values. (Or just flatten the bundle to work around this.)This pattern allows for lazily referenced circular dependencies as well.
Thus I do not think that using JavaScript Module Fragments would be required, although those would do the linking stage for you and thus be a lot easier to use than hand-writing this.
The text was updated successfully, but these errors were encountered: