0

In this post, the autor teaches how to make a binding from a NodeJS library to Reason. However, I want to create a binding for Google Maps Javascript API, which can't be installed through NPM. Rather, it's usually loaded in the bottom of <body> with <script> tag.

Also, Google Maps Javascript API only exports it's functions inside the function that has been passed as argument in url (callback=funcName). Will this work in Reason the same way as in raw JS?

How can I make this binding?

glennsl
  • 28,186
  • 12
  • 57
  • 75
Mateus Felipe
  • 1,071
  • 2
  • 19
  • 43

1 Answers1

1

The API is installed as a global, so you'd just bind to them as ordinary globals. And since Reason functions generate ordinary JavaScript functions the following is more or less equivalent to the example in the documentation you've linked:

type map;
[@bs.new] [@bs.scope ("google", "maps")] external make : (Dom.element, Js.t({..})) => map = "Map";

let initMap = () => {
  let map = make(mapElement, {
    "center": { "lat": -34.397, "lng": 150.644 },
    "zoom": 0
  });
};
glennsl
  • 28,186
  • 12
  • 57
  • 75
  • I'm going to test it and give you a response asap – Mateus Felipe May 24 '18 at 17:56
  • It worked, I only had to add a line binding the callback function to `window`, based on this question: https://stackoverflow.com/a/40575947/1924257. I'm going to edit your answer and accept it. – Mateus Felipe May 24 '18 at 22:24