3 ms·
Can you point to the feature request where you asked for 'new' on member functions, please? I would like to correct whatever response said it was in 'planning',
by yawaramin 8y ago
Can you point to the feature request where you asked for 'new' on member functions, please? I would like to correct whatever response said it was in 'planning', because it has been doable for a long time now. Here's some sample Reason that outputs pretty much exactly your above code:
module Web3 = {
module Eth = {
module Contract = {
type t;
[@bs.module "web3"] [@bs.scope "eth"] [@bs.new]
external make: (string, string, {. "from": string}) => t = "Contract";
};
};
};
let contract = Web3.Eth.Contract.make("ABI", "contactAddress", {"from": "from"});
You can try it out in the interactive playground.
Also, regarding this:
> You don't have to create a type for the whole class of the third party library, just the data you want Elm to manage.
That's exactly how Reason JavaScript bindings work too.
- splintercell 8y agoJust to be clear (and I now remember more details), I wanted to do bs.new with bs.send, but it wouldn't work. I am going to try what you suggested, but keep in mind I did go to the slack channel and tried asking this, none of their solutions looked like yours. Either way, intuitively @bs.new and @bs.send should be able to work together. https://github.com/BuckleScript/bucklescript/issues/2659 https://github.com/BuckleScript/bucklescript/issues/2659
- yawaramin 8y agoI see your problem (which is btw quite different from your original comment ;-) ). In a statically-typed language like Reason it's difficult to model dynamically-generated types like `hello_proto.Greeter`. One way is to use a functor ( https://v1.realworldocaml.org/v1/en/html/functors.html https://v1.realworldocaml.org/v1/en/html/functors.html ) but they have their limitations. This is why we have things like graphql_ppx which is a compiler extension to generate types from GraphQL schemas at compile-time. You'd need something like this (or, easier, a ReasonML-targeting gRPC/Protobuf client generator) to solve the issue brought up in GitHub.