[gjs: 1/2] doc: Fix documentation for dynamic imports
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 1/2] doc: Fix documentation for dynamic imports
- Date: Sat, 27 Mar 2021 19:15:54 +0000 (UTC)
commit 801755076cba6b8420db1fecdc174ee4d7266008
Author: Sonny Piers <sonny fastmail net>
Date: Sat Mar 27 14:59:38 2021 +0100
doc: Fix documentation for dynamic imports
doc/ESModules.md | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
---
diff --git a/doc/ESModules.md b/doc/ESModules.md
index 5c88ef98..7b966305 100644
--- a/doc/ESModules.md
+++ b/doc/ESModules.md
@@ -46,9 +46,17 @@ gjs -m module.js
ES modules cannot be loaded from strings at this time.
-`import('./module.js')` can be used to load modules from any GJS script
-or module.
-`import` will always default to loading a file as an ES Module.
+Besides the import expression syntax described above, Dynamic [`import()` statements][] can be used to load
modules from any GJS script or module.
+
+```js
+import('./animalSounds.js').then((module) => {
+ // module.default is the default export
+ // named exports are accessible as properties
+ // module.bark
+}).catch(logError)
+```
+
+Because `import()` is asynchronous, you will need a mainloop running.
### C API
@@ -170,10 +178,6 @@ import { ngettext as _ } from 'gettext';
_('Hello!');
```
-## `import()` expressions
-
-Dynamic [`import()` statements][] are not currently supported in GJS.
-
## `import.meta`
* {Object}
@@ -208,7 +212,7 @@ necessary.
An `import` statement can only reference an ES module.
`import` statements are permitted only in ES modules, but dynamic
-[`import()`][] expressions will be supported in legacy `imports` modules
+[`import()`][] expressions is supported in legacy `imports` modules
for loading ES modules.
When importing legacy `imports` modules, all `var` declarations are
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]