基于外部JS创建绑定
Create binding based on external JS
在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中,无法通过NPM安装。相反,它通常加载在带有 <script>
标签的 <body>
的底部。
此外,Google Maps Javascript API 仅在 url (callback=funcName
) 中作为参数传递的函数中导出它的函数。这在 Reason 中会像在原始 JS 中一样工作吗?
如何进行绑定?
API 是全局安装的,所以您只需 bind to them as ordinary globals。由于 Reason 函数生成普通的 JavaScript 函数,因此以下内容或多或少等同于您链接的文档中的示例:
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
});
};
在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中,无法通过NPM安装。相反,它通常加载在带有 <script>
标签的 <body>
的底部。
此外,Google Maps Javascript API 仅在 url (callback=funcName
) 中作为参数传递的函数中导出它的函数。这在 Reason 中会像在原始 JS 中一样工作吗?
如何进行绑定?
API 是全局安装的,所以您只需 bind to them as ordinary globals。由于 Reason 函数生成普通的 JavaScript 函数,因此以下内容或多或少等同于您链接的文档中的示例:
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
});
};