From f90baa618e42e3dd2da1b6f2fea7f72c72e0173d Mon Sep 17 00:00:00 2001 From: nojaf Date: Thu, 14 Nov 2024 15:59:50 +0100 Subject: [PATCH 1/2] Add namespace --- rescript.json | 1 + 1 file changed, 1 insertion(+) diff --git a/rescript.json b/rescript.json index b32c7f6..fc89a01 100644 --- a/rescript.json +++ b/rescript.json @@ -1,6 +1,7 @@ { "version": "0.0.0", "name": "@rescript/webapi", + "namespace": "WebAPI", "sources": [ { "dir": "src", From 60c22f91038a5394cbf8c9c57a24338f56a408f0 Mon Sep 17 00:00:00 2001 From: nojaf Date: Thu, 14 Nov 2024 16:03:07 +0100 Subject: [PATCH 2/2] Update docs --- docs/content/docs/index.mdx | 4 ++-- docs/content/docs/philosophy.mdx | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/content/docs/index.mdx b/docs/content/docs/index.mdx index b1a05e1..826ac96 100644 --- a/docs/content/docs/index.mdx +++ b/docs/content/docs/index.mdx @@ -36,7 +36,7 @@ export const rescriptJson = ` "@rescript/webapi", ], "bsc-flags": [ - "-open Global" + "-open WebAPI.Global" ] } `; @@ -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 \`.\` diff --git a/docs/content/docs/philosophy.mdx b/docs/content/docs/philosophy.mdx index 439f2f6..8e922bf 100644 --- a/docs/content/docs/philosophy.mdx +++ b/docs/content/docs/philosophy.mdx @@ -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") ``` @@ -43,6 +43,8 @@ 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 ``` @@ -50,6 +52,8 @@ 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