-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add require attribute. #68
base: master
Are you sure you want to change the base?
Conversation
```ocaml | ||
type t = private Ojs.t | ||
|
||
val module_t : t Lazy.t [@@js.require "myModule"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this work as well with a non-lazy binding?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will not work with non-lazy bindings yet. I force the use of lazyness to avoid requiring javascript module when they're not necessary.
But i can support both version (one lazy, and one non-lazy) if needed.
@Aaylor I didn't read the PR, but is |
Actually it's not supported, but it's just a simple case to add; but it will need a relaxed type for the A first solution would be to declare the With one of the two solution above, we would be able to write: val my_fun_module : (t1 -> ... -> tn) Lazy.t [@@js.require "myModule"] |
@dannywillems Well infact, with this version, it's possible to have function but it's not convenient. Requiring a function could be written as val my_fun_module : Ojs.t Lazy.t [@@js.require "myModule"] and then used as following: let _ =
let my_fun_m = Lazy.force my_fun_module in
let my_result_ojs = Ojs.apply my_fun_m [| (* ... *) |] in
(* ... *) I'm not sure that this is a philosophy of gen_js_api to give an |
| _ -> Some (id_of_expr (expr_of_payload k.loc v)) | ||
in | ||
require, require_ctx || require <> None | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure it's a good idea that this function returns a pair, since the second projection can be simply obtained from the first component and the require_ctx argument. My guess is that it would simplify the code a bit to move the corresponding logic at call sites (when needed).
Could you please provide a full example (if I am not mistaken, the js part is missing)? |
Sad to see this abandoned. Just stumbled across this problem when trying to bind some nodejs to jsoo with gen_js_api myself and hand to resort to defining globals and using |
All information about how works the require attribute are in the document REQUIRE.md; it contains three kind of usage, and the meaning of each automatic rules when under the require context.
Related to the discussion #66.