Skip to content

Commit 6552fbc

Browse files
committed
adios Js.Exn
1 parent c8dc2b8 commit 6552fbc

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

pages/docs/manual/latest/async-await.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,15 @@ You may use `try / catch` or `switch` to handle exceptions during async executio
130130
```res
131131
// For simulation purposes
132132
let authenticate = async () => {
133-
raise(Js.Exn.raiseRangeError("Authentication failed."))
133+
raise(Exn.raiseRangeError("Authentication failed."))
134134
}
135135
136136
let checkAuth = async () => {
137137
try {
138138
await authenticate()
139139
} catch {
140-
| Js.Exn.Error(e) =>
141-
switch Js.Exn.message(e) {
140+
| Exn.Error(e) =>
141+
switch Exn.message(e) {
142142
| Some(msg) => Console.log("JS error thrown: " ++ msg)
143143
| None => Console.log("Some other exception has been thrown")
144144
}
@@ -152,14 +152,14 @@ You may unify error and value handling in a single switch as well:
152152

153153
```res
154154
let authenticate = async () => {
155-
raise(Js.Exn.raiseRangeError("Authentication failed."))
155+
raise(Exn.raiseRangeError("Authentication failed."))
156156
}
157157
158158
let checkAuth = async () => {
159159
switch await authenticate() {
160160
| _ => Console.log("ok")
161-
| exception Js.Exn.Error(e) =>
162-
switch Js.Exn.message(e) {
161+
| exception Exn.Error(e) =>
162+
switch Exn.message(e) {
163163
| Some(msg) => Console.log("JS error thrown: " ++ msg)
164164
| None => Console.log("Some other exception has been thrown")
165165
}

pages/docs/manual/latest/exception.mdx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ throw {
134134

135135
## Catching JS Exceptions
136136

137-
To distinguish between JavaScript exceptions and ReScript exceptions, ReScript namespaces JS exceptions under the `Js.Exn.Error(payload)` variant. To catch an exception thrown from the JS side:
137+
To distinguish between JavaScript exceptions and ReScript exceptions, ReScript namespaces JS exceptions under the `Exn.Error(payload)` variant. To catch an exception thrown from the JS side:
138138

139139

140140
Throw an exception from JS:
@@ -158,25 +158,25 @@ try {
158158
// call the external method
159159
someJSFunctionThatThrows()
160160
} catch {
161-
| Js.Exn.Error(obj) =>
162-
switch Js.Exn.message(obj) {
161+
| Exn.Error(obj) =>
162+
switch Exn.message(obj) {
163163
| Some(m) => Console.log("Caught a JS exception! Message: " ++ m)
164164
| None => ()
165165
}
166166
}
167167
```
168168

169-
The `obj` here is of type `Js.Exn.t`, intentionally opaque to disallow illegal operations. To operate on `obj`, do like the code above by using the standard library's [`Js.Exn`](api/js/exn) module's helpers.
169+
The `obj` here is of type `Exn.t`, intentionally opaque to disallow illegal operations. To operate on `obj`, do like the code above by using the standard library's [`Exn`](api/js/exn) module's helpers.
170170

171171
## Raise a JS Exception
172172

173-
`raise(MyException)` raises a ReScript exception. To raise a JavaScript exception (whatever your purpose is), use `Js.Exn.raiseError`:
173+
`raise(MyException)` raises a ReScript exception. To raise a JavaScript exception (whatever your purpose is), use `Exn.raiseError`:
174174

175175
<CodeTab labels={["ReScript", "JS Output"]}>
176176

177177
```res example
178178
let myTest = () => {
179-
Js.Exn.raiseError("Hello!")
179+
Exn.raiseError("Hello!")
180180
}
181181
```
182182
```js
@@ -257,7 +257,7 @@ try {
257257
} catch {
258258
| Not_found => ... // catch a ReScript exception
259259
| Invalid_argument(_) => ... // catch a second ReScript exception
260-
| Js.Exn.Error(obj) => ... // catch the JS exception
260+
| Exn.Error(obj) => ... // catch the JS exception
261261
}
262262
```
263263

pages/docs/manual/latest/import-from-export-to-js.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ var studentName = Student;
102102
<CodeTab labels={["ReScript", "JS Output (Module)"]}>
103103
```rescript
104104
@module({from: "./myJson.json", with: {type_: "json", \"some-exotic-identifier": "someValue"}})
105-
external myJson: Js.Json.t = "default"
105+
external myJson: JSON.t = "default"
106106
107107
Console.log(myJson)
108108
```
@@ -130,7 +130,7 @@ Also notice `type_`. Since `type` is a reserved keyword in ReScript, you can use
130130
Leveraging JavaScript's [dynamic `import`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import) to reduce bundle size and lazy load code as needed is easy in ReScript. It's also a little bit more convenient than in regular JavaScript because you don't need to keep track of file paths manually with ReScript's module system.
131131

132132
### Dynamically Importing Parts of a Module
133-
Use the `Js.import` function to dynamically import a specific part of a module. Put whatever `let` binding you want to import in there, and you'll get a `promise` back resolving to that specific binding.
133+
Use the `import` function to dynamically import a specific part of a module. Put whatever `let` binding you want to import in there, and you'll get a `promise` back resolving to that specific binding.
134134

135135
Let's look at an example. Imagine the following file `MathUtils.res`:
136136

@@ -145,7 +145,7 @@ Now let's dynamically import the add function in another module, e.g. `App.res`:
145145
```rescript
146146
// App.res
147147
let main = async () => {
148-
let add = await Js.import(MathUtils.add)
148+
let add = await import(MathUtils.add)
149149
let onePlusOne = add(1, 1)
150150
151151
Console.log(onePlusOne)
@@ -164,7 +164,7 @@ async function main() {
164164
</CodeTab>
165165

166166
### Dynamically Importing an Entire Module
167-
The syntax for importing a whole module looks a little different, since we are operating on the module syntax level; instead of using `Js.import`, you may simply `await` the module itself:
167+
The syntax for importing a whole module looks a little different, since we are operating on the module syntax level; instead of using `import`, you may simply `await` the module itself:
168168
<CodeTab labels={["ReScript", "JS Output (Module)"]}>
169169
```rescript
170170
// App.res

0 commit comments

Comments
 (0)