Make `rustyscript` global object optional & able to be renamed
ac-z opened this issue · 2 comments
Right now, registered functions are made available under the functions
and async_functions
proxies within the global rustyscript
object, alongside the essential functions bail
and register_entrypoint
.
This is a good default, but I think it would be good to allow more flexibility here. I have the following additions to the API in mind:
- An optional "runtime name" in RuntimeOptions which determines the name of the global object. If
None
, default to the current name,rustyscript
. - Optional exclusion of these lines, either via a feature flag or a boolean in RuntimeOptions. This is important for sufficiently complex use cases, which may need to organize many ops into categories (e.g.
appname.category.subcategory.foo()
)
rustyscript/src/ext/rustyscript/rustyscript.js
Lines 35 to 52 in 4745154
- Maybe this code snippet should be its own tiny extension, outside of rustyscript.js? Then it could be handled like every other optional extension.
Things to consider
- There are a bunch of places in the docs we'd have to diligently change.
- If the global object is turned off, the "runtime name" option in RuntimeOptions wouldn't do anything. Perhaps this is a point in favor of using a feature flag, as we can ensure that option is only available when there's a global object to be named in the first place.
- RuntimeOptions is getting crowded.
I really don't see the point
It's JavaScript, users can just rename it, or make their own object referencing mine
This would just add complexity
Users could just as easily:
globalThis.myFunctions = {
rustyscript.functions.a, rustyscript.functions.b
}
I really don't see the point It's JavaScript, users can just rename it, or make their own object referencing mine
Was under the impression that freezing in JavaScript doesn't let you delete or rename. Closing.