File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed
Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff 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
100105If 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
130135struct MyModule ;
131136globals_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.
You can’t perform that action at this time.
0 commit comments