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/philosophy.mdx
+7-16Lines changed: 7 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,13 +16,12 @@ The bindings are generated from the [MDN Web API documentation](https://develope
16
16
17
17
In other words, if you are searching for a specific JavaScript binding, begin your journey at the [MDN Web API documentation](https://developer.mozilla.org/en-US/docs/Web/API) and determine which module contains your sample. Ensure that the module is available in the bindings by checking the specific API. Please [open an issue](https://github.com/rescript-lang/experimental-rescript-webapi/issues/new/choose) if you require an API that is not yet present.
18
18
19
-
Each API will have its interface and auxiliary types in a module named after the API, suffixed with `API` to prevent collisions with the type module.
19
+
Each feature is grouped under a `WebApi.<Feature>`module so related interfaces and helper modules stay together without relying on flat package-wide names.
20
20
21
21
```ReScript
22
-
open WebAPI.Global
23
-
open WebAPI.DOMAPI
22
+
open WebApi.DOM.Global
24
23
25
-
let myElement: element = document->Document.createElement( ~localName = "div")
24
+
let myElement: WebApi.DOM.Types.element = document->WebApi.DOM.Document.createElement("div")
26
25
```
27
26
28
27
## Interfaces
@@ -44,18 +43,10 @@ JavaScript supports function overloads, where a function can have multiple signa
44
43
In some cases, type conversion will be required. Subtypes can safely be cast to their base type using conversion helpers within their module.
45
44
46
45
```ReScript
47
-
open WebAPI
46
+
open WebApi.DOM.Global
48
47
49
-
let element: element = document->Document.createElement( ~localName = "div")
50
-
let node: node = element->Element.asNode
48
+
let element: WebApi.DOM.Types.element = document->WebApi.DOM.Document.createElement("div")
49
+
let node: WebApi.DOM.Types.node = element->WebApi.DOM.Element.asNode
51
50
```
52
51
53
-
Any other conversions can be performed using the `Base.unsafeConversation` helper. This should be done with caution, as it can lead to runtime errors.
54
-
55
-
```ReScript
56
-
open WebAPI
57
-
58
-
let element: element = document->Document.createElement( ~localName = "div")
59
-
// This is potentially unsafe, as the type system cannot guarantee the conversion
60
-
let divElement: htmlDivElement = element->Base.unsafeConversation
61
-
```
52
+
Any other conversions should be treated as unsafe casts and used with caution, because the type system cannot guarantee they are valid at runtime.
0 commit comments