Open
Description
Every property accessor in the entire project is an external. When bs-webapi was created that was the only way to do it. Since then records are compiled to objects so we can use (private) record types to represent the properties.
For example, DomRect:
type t = Dom.domRect;
[@bs.new] external make : (~x: float, ~y: float, ~width: float, ~height: float) => t = "DOMRect"; /* experimental */
[@bs.get] external top : t => float = "";
[@bs.get] external bottom : t => float = "";
[@bs.get] external left : t => float = "";
[@bs.get] external right : t => float = "";
[@bs.get] external height : t => float = "";
[@bs.get] external width : t => float = "";
[@bs.get] external x : t => float = "";
[@bs.get] external y : t => float = "";
Can now be implemented as:
type t =
pri {
top: float,
bottom: float,
left: float,
right: float,
height: float,
width: float,
x: float,
y: float,
};
[@bs.new] external make: (~x: float, ~y: float, ~width: float, ~height: float) => t = "DOMRect"; /* experimental */
This is still up for debate, because by not using the ReScript-provided abstract types like Dom.domRect
this will break compatibility with other DOM-related libraries. The improved ease of use is worth it in property-heavy types like DOMRect
, but perhaps it should be used sparingly.