From 4ce940d367110ff16e4f0f21828435fd7a5133f7 Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Wed, 8 Jun 2022 17:02:54 -0700 Subject: [PATCH] Add motivating example for host defaults --- README.md | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7393e77..919fa0d 100644 --- a/README.md +++ b/README.md @@ -436,7 +436,35 @@ interface Loader { } ``` -### Design Rationales +## Motivating Examples and Design Rationales + +### Multiple-instantiation + +This example illustrates the use of a new loader to support multiple +instantiation of modules, reusing the host's loader and static module record +memos as a cache. +This example creates five instances of the example module and its transitive +dependencies. + +```js +for (let i = 0; i < 5; i += 1) { + new Loader().import('https://example.com/example.js'); +} +``` + +Assuming that the language separately adopted hypothetical `import static` +syntax to defer execution but load a module and its transitive dependencies, a +bundler would be able to observe the need to capture the example module and its +transitive dependencies, such that the *only* instances are in guest loaders. + +```js +import static 'https://example.com/example.js'; +for (let i = 0; i < 5; i += 1) { + new Loader().import('https://example.com/example.js'); +} +``` + +### Thenable Module Hazard An exported value named `then` can be statically imported, but dynamic import confuses the module namespace for a thenable object.