You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/content/docs/api-surface.mdx
+14-20Lines changed: 14 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,8 +37,9 @@ Global singleton APIs such as `Location`, `Crypto`, and `Performance` expose dir
37
37
functions and properties. Object-owned APIs still use the value as the receiver.
38
38
39
39
```ReScript
40
+
let href = WebAPI.Location.href
40
41
let location = WebAPI.Location.current
41
-
let href = location.href
42
+
let sameHref = location.href
42
43
43
44
WebAPI.Location.reload()
44
45
```
@@ -51,8 +52,7 @@ helper modules.
51
52
```ReScript
52
53
let req: WebAPI.Request.t = WebAPI.Request.fromURL("https://example.com")
53
54
let headers = WebAPI.Headers.make()
54
-
let document = WebAPI.Window.current->WebAPI.Window.document
55
-
let element = document->WebAPI.Document.createElement("button")
55
+
let element: WebAPI.Element.t = WebAPI.Document.createElement("button")
56
56
```
57
57
58
58
With `"-open WebAPI"`, the same modules can be referenced without the `WebAPI.` prefix:
@@ -266,30 +266,24 @@ let redirect = WebAPI.Response.redirect(~url="/login", ~status=302)
266
266
267
267
## DOM
268
268
269
-
DOM values are operated on through public interface modules.
270
-
`WebAPI.Element` is the method module for element values. When you need to name the element type explicitly, use `WebAPI.DOM.element`; most examples can rely on inference from `Document.createElement`, `Document.querySelector`, and related DOM helpers.
269
+
Common document entry points are exposed directly on `WebAPI.Document`, bound to
270
+
`globalThis.document`. DOM object properties use dot syntax, and instance methods stay
271
+
receiver-based through the owner module. When you need to name an element type explicitly,
272
+
use `WebAPI.Element.t`.
271
273
272
274
```ReScript
273
-
let document = WebAPI.Window.current->WebAPI.Window.document
Copy file name to clipboardExpand all lines: docs/content/docs/contributing/api-module-structure.mdx
+8-1Lines changed: 8 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -64,7 +64,14 @@ type rec node = {
64
64
and element = Base__Element.t
65
65
```
66
66
67
-
For shared DOM base interfaces such as `Element`, keep the root type as a thin opaque owner such as `Base__Element.t`. The DOM API module can expose `DOM.element` as a public alias while method modules use `DomTypes.element`.
67
+
Public interface modules own their public `t` type. For example, `Element.res` exposes
68
+
`Element.t`, `Document.res` exposes `Document.t`, and `Location.res` exposes `Location.t`.
69
+
These public `t` types are the names consumers should use in annotations.
70
+
71
+
When an interface needs a shared structural owner across APIs or inheritance chains, keep
72
+
that shared shape in a base module such as `Base__Element.t`. The public interface module
73
+
then aliases the base shape as its own `t`, while generated structural modules can keep
74
+
using internal aliases such as `DomTypes.element` where needed.
`Element.res` is a method module. It does not define the `element` type directly. The shared DOM element type is a thin opaque base handle threaded back into DOM through aliases:
81
+
Public interface modules expose their own `t` type even when the underlying shape is shared.
82
+
For a shared DOM object base, keep the structural owner in a base module and make the public
83
+
interface module a same-type alias of that base:
82
84
83
85
```ReScript
84
86
// Base__Element.res
85
87
type t = private {}
86
88
87
-
// DomTypes.res
88
-
type element = Base__Element.t = private {...Base__Element.t}
89
-
90
89
// Element.res
91
-
include Impl({type t = DomTypes.element})
90
+
type t = Base__Element.t = {...Base__Element.t}
91
+
92
+
// DomTypes.res
93
+
type element = Base__Element.t = {...Base__Element.t}
92
94
```
93
95
94
-
This keeps `Element.Impl` reusable for element subtypes while giving the package one shared base element handle. Subtype modules should continue to include the nearest base method implementation:
96
+
This keeps `Element.t` as the public type name while still allowing generated DOM structural
97
+
types to share the same object identity. `Element.Impl` remains reusable for element subtypes,
98
+
and subtype modules should continue to include the nearest base method implementation:
95
99
96
100
```ReScript
97
101
// HTMLElement.res
@@ -101,4 +105,4 @@ include Element.Impl({type t = DomTypes.htmlElement})
101
105
include HTMLElement.Impl({type t = DomTypes.htmlButtonElement})
102
106
```
103
107
104
-
Use `asElement` when a subtype needs to be passed to a function that expects the shared element type.
108
+
Use `asElement` when a subtype needs to be passed to a function that expects `Element.t`.
Copy file name to clipboardExpand all lines: docs/content/docs/philosophy.mdx
+4-8Lines changed: 4 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,14 +20,12 @@ In other words, if you are searching for a specific JavaScript binding, begin yo
20
20
The bindings are exposed under the `WebAPI` namespace with the same flat module structure as the original package.
21
21
22
22
```ReScript
23
-
open WebAPI.DOM
24
-
25
-
let myElement: WebAPI.DOM.element = document->WebAPI.Document.createElement("div")
23
+
let myElement: WebAPI.Element.t = WebAPI.Document.createElement("div")
26
24
let id = myElement.id
27
25
```
28
26
29
27
Consumers can also configure `rescript.json` with `"compiler-flags": ["-open WebAPI"]`
30
-
when they want to use modules such as `DOM`, `Document`, and `Element` without the
28
+
when they want to use modules such as `Document`, `Element`, and `Location` without the
31
29
`WebAPI.` prefix.
32
30
33
31
## Interfaces
@@ -40,7 +38,7 @@ Methods are modeled as functions in a separate module. The idea is that these wi
40
38
41
39
Inherited methods are duplicated in the inheriting module to eliminate the need to cast the type to the base type.
42
40
43
-
For DOM elements, `WebAPI.Element` is the method module. The element type itself is exposed as `WebAPI.DOM.element`. Most code does not need to annotate the type because functions such as `Document.createElement` and `Document.querySelector` already return it.
41
+
For DOM elements, `WebAPI.Element.t` is the public element type and `WebAPI.Element` is the method module. Most code does not need to annotate the type because functions such as `Document.createElement` and `Document.querySelector` already return it.
44
42
45
43
### Overloads
46
44
@@ -51,9 +49,7 @@ JavaScript supports function overloads, where a function can have multiple signa
51
49
In some cases, type conversion will be required. Subtypes can safely be cast to their base type using conversion helpers within their module.
52
50
53
51
```ReScript
54
-
open WebAPI.DOM
55
-
56
-
let element: WebAPI.DOM.element = document->WebAPI.Document.createElement("div")
52
+
let element: WebAPI.Element.t = WebAPI.Document.createElement("div")
0 commit comments