Skip to content

Add namespace #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/content/docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const rescriptJson = `
"@rescript/webapi",
],
"bsc-flags": [
"-open Global"
"-open WebAPI.Global"
]
}
`;
Expand All @@ -48,7 +48,7 @@ export const rescriptJson = `
After installing the package , you can use bindings for the various Web APIs as defined in [MDN](https://developer.mozilla.org/en-US/docs/Web/API).

export const rescriptSample = `
// Note that this only works when you added the \`-open Global\` bsc flag.
// Note that this only works when you added the \`-open WebAPI.Global\` bsc flag.
let location = window.location

// Access properties using \`.\`
Expand Down
8 changes: 6 additions & 2 deletions docs/content/docs/philosophy.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ In other words, if you are searching for a specific JavaScript binding, begin yo
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.

```ReScript
open Global
open DOMAPI
open WebAPI.Global
open WebAPI.DOMAPI

let myElement: element = document->Document.createElement( ~localName = "div")
```
Expand All @@ -43,13 +43,17 @@ JavaScript supports function overloads, where a function can have multiple signa
In some cases, type conversion will be required. Subtypes can safely be cast to their base type using conversion helpers within their module.

```ReScript
open WebAPI

let element: element = document->Document.createElement( ~localName = "div")
let node: node = element->Element.asNode
```

Any other conversions can be performed using the `Prelude.unsafeConversation` helper. This should be done with caution, as it can lead to runtime errors.

```ReScript
open WebAPI

let element: element = document->Document.createElement( ~localName = "div")
// This is potentially unsafe, as the type system cannot guarantee the conversion
let divElement: htmlDivElement = element->Prelude.unsafeConversation
Expand Down
1 change: 1 addition & 0 deletions rescript.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"version": "0.0.0",
"name": "@rescript/webapi",
"namespace": "WebAPI",
"sources": [
{
"dir": "src",
Expand Down