Skip to content

Commit 2e3b9b5

Browse files
committed
Improve readme
1 parent bbe2be7 commit 2e3b9b5

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,17 @@ impl ModuleDefExt<MyModuleOptions> for MyModule {
8989

9090
fn globals(globals: &Object<'_>, options: &MyModuleOptions) -> Result<()> {
9191
// Set your globals here
92-
globals.set("user", options.user.clone())?;
92+
globals.set("global_user", options.user.clone())?;
9393
Ok(())
9494
}
9595
}
9696
```
9797

98+
At runtime, this module results in:
99+
100+
- A global `global_user` variable
101+
- An importable module `import { user } from "my-module"`
102+
98103
### Globals only
99104

100105
If you only need to set globals and do **NOT** want an actual module that the Javascript can import, use `GlobalsOnly` for the implementation.
@@ -129,7 +134,10 @@ use rquickjs_module::globals_only_module;
129134

130135
struct MyModule;
131136
globals_only_module!(MyModule, |globals| {
132-
// Custom globals initialization code here
137+
// Set your globals here
138+
globals.set("hello", "world".to_string())?;
133139
Ok(())
134140
});
135141
```
142+
143+
Both result in a global variable named `hello` begin available at runtime.

0 commit comments

Comments
 (0)