Closed
Description
One recurring question we get is how to bind to a module itself, how to bind to a default, how to bind to a nested value and how to bind to a global one. I'm proposing that we unify these through:
(* var X = require('x'); X.add *)
external add : int -> int -> int = "" [@@bs.require ("x", "add")]
(* bind to the module itself *)
external fs : someType = "" [@@bs.require "fs"]
(* window.location *)
external location : someType = "" [@@bs.require ("window", "location")][@@bs.global]
(* bind to document *)
external dom : dom = "" [@@bs.require "document"][@@bs.global]
Characteristics:
- It'll always be
= ""
. This makes things much more consistent for newcomers. It's a recurring question of where to put what. Maybe we can choose another format now thanks to this. - People also ask whether to use
[@@bs.val "Math.imul"]
or thebs.scope
equivalent, etc. - Composes with bs.new and the rest as expected.
- Unifies
bs.module
,bs.scope
,bs.val
under a similar looking API. Nobs.module
module renaming facility, but that's rather rare. These are still kept for backward compat. - Resolves the question "what if I want to bind to a module that's global?" through
bs.global
, which is easier to remember. - Might have some nice opportunities to work with bs.get/set.