Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This is the official documentation platform for the [ReScript](https://rescript-

## System Requirements

- `node@18` or higher
- `node@20` or higher
- `npm@10` or higher

## Setup
Expand All @@ -28,10 +28,7 @@ npm i
# Initial build
npx rescript

# Only needed for initial clone (or content H2 changes)
npm run update-index

# Build the index data
# Build the index data. Only needed for initial clone (or content H2 changes)
npm run update-index

# In a new tab
Expand Down
46 changes: 24 additions & 22 deletions compilers/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions compilers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"main": "index.js",
"license": "MIT",
"dependencies": {
"@rescript/core": "^0.6.0",
"@rescript/core": "^1.3.0",
"@rescript/react": "^0.12.0",
"rescript-1000": "npm:[email protected]",
"rescript-1010": "npm:[email protected]",
"rescript-1100": "npm:[email protected]",
"rescript-1110": "npm:[email protected]-rc.8",
"rescript-1110": "npm:[email protected]",
"rescript-820": "npm:[email protected]",
"rescript-902": "npm:[email protected]",
"rescript-912": "npm:[email protected]"
Expand Down
2 changes: 1 addition & 1 deletion misc_docs/syntax/decorator_module.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var root = Path.dirname("/User/github");
<CodeTab labels={["ReScript", "JS Output (Module)"]}>
```rescript
@module({from: "./myJson.json", with: {type_: "json", \"some-exotic-identifier": "someValue"}})
external myJson: Js.Json.t = "default"
external myJson: JSON.t = "default"

Console.log(myJson)
```
Expand Down
12 changes: 6 additions & 6 deletions pages/docs/manual/latest/async-await.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ You may use `try / catch` or `switch` to handle exceptions during async executio
```res
// For simulation purposes
let authenticate = async () => {
raise(Js.Exn.raiseRangeError("Authentication failed."))
raise(Exn.raiseRangeError("Authentication failed."))
}

let checkAuth = async () => {
try {
await authenticate()
} catch {
| Js.Exn.Error(e) =>
switch Js.Exn.message(e) {
| Exn.Error(e) =>
switch Exn.message(e) {
| Some(msg) => Console.log("JS error thrown: " ++ msg)
| None => Console.log("Some other exception has been thrown")
}
Expand All @@ -152,14 +152,14 @@ You may unify error and value handling in a single switch as well:

```res
let authenticate = async () => {
raise(Js.Exn.raiseRangeError("Authentication failed."))
raise(Exn.raiseRangeError("Authentication failed."))
}

let checkAuth = async () => {
switch await authenticate() {
| _ => Console.log("ok")
| exception Js.Exn.Error(e) =>
switch Js.Exn.message(e) {
| exception Exn.Error(e) =>
switch Exn.message(e) {
| Some(msg) => Console.log("JS error thrown: " ++ msg)
| None => Console.log("Some other exception has been thrown")
}
Expand Down
14 changes: 7 additions & 7 deletions pages/docs/manual/latest/exception.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ throw {

## Catching JS Exceptions

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:
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:


Throw an exception from JS:
Expand All @@ -158,25 +158,25 @@ try {
// call the external method
someJSFunctionThatThrows()
} catch {
| Js.Exn.Error(obj) =>
switch Js.Exn.message(obj) {
| Exn.Error(obj) =>
switch Exn.message(obj) {
| Some(m) => Console.log("Caught a JS exception! Message: " ++ m)
| None => ()
}
}
```

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.
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.

## Raise a JS Exception

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

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

```res example
let myTest = () => {
Js.Exn.raiseError("Hello!")
Exn.raiseError("Hello!")
}
```
```js
Expand Down Expand Up @@ -257,7 +257,7 @@ try {
} catch {
| Not_found => ... // catch a ReScript exception
| Invalid_argument(_) => ... // catch a second ReScript exception
| Js.Exn.Error(obj) => ... // catch the JS exception
| Exn.Error(obj) => ... // catch the JS exception
}
```

Expand Down
8 changes: 4 additions & 4 deletions pages/docs/manual/latest/import-from-export-to-js.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ var studentName = Student;
<CodeTab labels={["ReScript", "JS Output (Module)"]}>
```rescript
@module({from: "./myJson.json", with: {type_: "json", \"some-exotic-identifier": "someValue"}})
external myJson: Js.Json.t = "default"
external myJson: JSON.t = "default"

Console.log(myJson)
```
Expand Down Expand Up @@ -130,7 +130,7 @@ Also notice `type_`. Since `type` is a reserved keyword in ReScript, you can use
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.

### Dynamically Importing Parts of a Module
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.
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.

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

Expand All @@ -145,7 +145,7 @@ Now let's dynamically import the add function in another module, e.g. `App.res`:
```rescript
// App.res
let main = async () => {
let add = await Js.import(MathUtils.add)
let add = await import(MathUtils.add)
let onePlusOne = add(1, 1)

Console.log(onePlusOne)
Expand All @@ -164,7 +164,7 @@ async function main() {
</CodeTab>

### Dynamically Importing an Entire Module
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:
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:
<CodeTab labels={["ReScript", "JS Output (Module)"]}>
```rescript
// App.res
Expand Down
4 changes: 2 additions & 2 deletions pages/docs/manual/latest/primitive-types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ As `bigint` is a different data type than `int`, it's necessary to open the corr
<CodeTab labels={["ReScript", "JS Output"]}>

```res example
open! Js.BigInt
open! BigInt

let a = 9007199254740991n + 9007199254740991n
let b = 2n ** 2n
Expand All @@ -198,7 +198,7 @@ It also supports all the bitwise operations, except unsigned shift right (`>>>`)
<CodeTab labels={["ReScript", "JS Output"]}>

```res example
open! Js.BigInt
open! BigInt

let a = land(1n, 1n)
let b = lor(1n, 1n)
Expand Down
2 changes: 1 addition & 1 deletion pages/docs/react/latest/beyond-jsx.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ type props<'className, 'children, 'ref> = {

let make = (
{?className, children, _}: props<'className, 'children, ReactRef.currentDomRef>,
ref: Js.Nullable.t<ReactRef.currentDomRef>,
ref: Nullable.t<ReactRef.currentDomRef>,
) =>
make(~className, ~children, ~ref, ())
```
Expand Down
12 changes: 6 additions & 6 deletions pages/docs/react/latest/forwarding-refs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ module FancyInput = {

@react.component
let make = () => {
let input = React.useRef(Js.Nullable.null)
let input = React.useRef(Nullable.null)

let focusInput = () =>
input.current
->Js.Nullable.toOption
->Belt.Option.forEach(input => input->focus)
->Nullable.toOption
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is also Nullable.forEach now

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 6d659e5

->Option.forEach(input => input->focus)

let onClick = _ => focusInput()

Expand Down Expand Up @@ -96,7 +96,7 @@ module FancyInput = {
<input
type_="text"
?className
ref=?{Js.Nullable.toOption(ref)->Belt.Option.map(ReactDOM.Ref.domRef)}
ref=?{Nullable.toOption(ref)->Option.map(ReactDOM.Ref.domRef)}
/>
children
</div>
Expand All @@ -107,10 +107,10 @@ module FancyInput = {

@react.component
let make = () => {
let input = React.useRef(Js.Nullable.null)
let input = React.useRef(Nullable.null)

let focusInput = () =>
input.current->Js.Nullable.toOption->Belt.Option.forEach(input => input->focus)
input.current->Nullable.toOption->Option.forEach(input => input->focus)

let onClick = _ => focusInput()

Expand Down
4 changes: 2 additions & 2 deletions pages/docs/react/latest/hooks-reducer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ type state = {
let reducer = (state, action) =>
switch action {
| AddTodo(content) =>
let todos = Js.Array2.concat(
let todos = Array.concat(
state.todos,
[{id: state.nextId, content: content, completed: false}],
)
{todos: todos, nextId: state.nextId + 1}
| RemoveTodo(id) =>
let todos = Js.Array2.filter(state.todos, todo => todo.id !== id)
let todos = Array.filter(state.todos, todo => todo.id !== id)
{...state, todos: todos}
| ToggleTodo(id) =>
let todos = Belt.Array.map(state.todos, todo =>
Expand Down
12 changes: 6 additions & 6 deletions pages/docs/react/latest/hooks-ref.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ More infos on direct DOM manipulation can be found in the [Refs and the DOM](./r

@react.component
let make = () => {
let inputEl = React.useRef(Js.Nullable.null)
let inputEl = React.useRef(Nullable.null)

let onClick = _ => {
inputEl.current
->Js.Nullable.toOption
->Belt.Option.forEach(input => input->focus)
->Nullable.toOption
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nullable.forEach

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 6d659e5

->Option.forEach(input => input->focus)
}

<>
Expand Down Expand Up @@ -104,15 +104,15 @@ Reusing the example from our [Refs and the DOM](./refs-and-the-dom#callback-refs

@react.component
let make = () => {
let textInput = React.useRef(Js.Nullable.null)
let textInput = React.useRef(Nullable.null)
let setTextInputRef = element => {
textInput.current = element;
}

let focusTextInput = _ => {
textInput.current
->Js.Nullable.toOption
->Belt.Option.forEach(input => input->focus)
->Nullable.toOption
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nullable.forEach

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 6d659e5

->Option.forEach(input => input->focus)
}

<div>
Expand Down
Loading