-
Notifications
You must be signed in to change notification settings - Fork 469
Allow to combine bs.new with more attrs #2659
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
Comments
It is something we did not support yet: I feel it is very hard to type it statically, any proposal is welcome |
Some rough ideas: external constructor1 : ('a0, 'b) Js.constructor -> 'a0 -> 'b = "#new"
external constructor2 : ('a0, 'a1, 'b) Js.constructor2 -> 'a0 -> 'a1 -> 'b = "#new"
external constructor3 : ('a0, 'a1, 'a2, 'b) Js.constructor3 -> 'a0 -> 'a1 -> 'a2 -> 'b = "#new" |
@bobzhang Is that something being considered for the future? I am trying to figure out the best way to use gRPC from Reason/OCaml. |
@bobzhang how does Perhaps I am misunderstanding... |
Is there any way by which this can be achieved using Bucklescript, howsoever hacky it may be? var client = new hello_proto.Greeter('localhost:50051',...); |
A better solution in this particular case would be to write a gRPC compiler that targets OCaml/Reason. https://github.com/mransan/ocaml-protoc is a good head start but it doesn't support services ( mransan/ocaml-protoc#126 ). |
@yawaramin that isn't a terrible idea, however I believe it's OT for this issue. At the time, it seemed like the right idea to provide bindings to grpc-node |
This is a similar kind of dynamism to #2765 , we can do a similar hacky workaround for the time being. E.g. translating Javier's code, /* Grpc.re */
type t;
[@bs.module "grpc"] external load: string => t;
/* Greeter.re */
let _helloProto = Grpc.load("/proto/path");
/* ^ this... */
type t;
[@bs.new] external make: string => t = "_helloProto.helloworld.Greeter";
/* ...needs to be the same as this ^ */ This again relies on BuckleScript not mangling names, and is unsafe, but no more so than |
This is what I ended up doing: let newHack: a => b => t =
[%bs.raw {|(Constructor, arg) => new Constructor(arg)|}]; Where |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
There was a conversation in Discord about some bindings to a JS library:
Because
bs.new
can only be combined withbs.module
(but in this case, it'd be needed withbs.send
) I believe there is no way to express this in BuckleScript (or i havent' been able to find it).cc @thangngoc89.
The text was updated successfully, but these errors were encountered: