I want to generate javascript function called Publisher
from ReasonML so that i can use it in other files as for example:
const publisher = new Publisher("Prasad", "email@email.com", "team@email.com", "rill")
const req = Publisher.toAPI(publisher) // returns {name: "Prasad", email: "email@email.com", team: "team@email.com", service: "rill"}
To achieve above functionality, I wrote ReasonML code in file named Util.re which is:
type publisher = {
name: string,
emailID: string,
teamEmailID: string,
serviceName: string,
};
type publisherReqBody = {
name: string,
email: string,
team: string,
publisher: string,
};
module Publisher = {
let toAPI = (p: publisher) => {
name: p.name,
email: p.emailID,
team: p.teamEmailID,
publisher: p.serviceName,
};
[@bs.new] external create: unit => publisher = "Publisher";
};
After compilation from ReasonML to JavaScript using BuckleScript, what i got
// Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE
function toAPI(p) {
return {
name: p.name,
email: p.emailID,
team: p.teamEmailID,
publisher: p.serviceName
};
}
var Publisher = {
toAPI: toAPI
};
export {
Publisher ,
}
I am not sure why [@bs.new] external create: unit => publisher = "Publisher";
line not working. I have tried for an hour but no use.
My question:
how to achieve functionality i mentioned in first snippet in JavaScript which is compiled from ReasonML
Thanks a lot!