Skip to content

Migrate to Core #876

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 8 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
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
4 changes: 2 additions & 2 deletions pages/docs/react/latest/lazy-components.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ Now we can dynamically import the `<Title/>` component by passing the result of
```rescript
// SomeOtherFile.res
module LazyTitle = {
let make = React.lazy_(() => Js.import(Title.make))
let make = React.lazy_(() => import(Title.make))
}

let titleJsx = <LazyTitle text="Hello!" />
```

That's all the code we need! The new `<LazyTitle />` component behaves exactly the same as the wrapped `<Title />` component, but will be lazy loaded via React's built-in lazy mechanism.

> You can read more about `Js.import` and dynamic import in ReScript in [this part of the documentation](/docs/manual/latest/import-from-export-to-js#dynamic-import).
> You can read more about `import` and dynamic import in ReScript in [this part of the documentation](/docs/manual/latest/import-from-export-to-js#dynamic-import).
8 changes: 4 additions & 4 deletions pages/docs/react/latest/migrate-react.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ module FancyInput = {
<input
type_="text"
?className
ref=?{ref_->Js.Nullable.toOption->Belt.Option.map(ReactDOM.Ref.domRef)}
ref=?{ref_->Nullable.toOption->Option.map(ReactDOM.Ref.domRef)}
/>
children
</div>
Expand All @@ -157,7 +157,7 @@ module FancyInput = {

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

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

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

<div>
<FancyInput ref=input>
Expand Down
18 changes: 9 additions & 9 deletions pages/docs/react/latest/refs-and-the-dom.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ let value = myRef.current
```

The value of the ref differs depending on the type of the node:
- When the ref attribute is used on an HTML element, the ref passed via `ReactDOM.Ref.domRef` receives the underlying DOM element as its current property (type of `React.ref<Js.Nullable.t<Dom.element>>`)
- When the ref attribute is used on an HTML element, the ref passed via `ReactDOM.Ref.domRef` receives the underlying DOM element as its current property (type of `React.ref<Nullable.t<Dom.element>>`)
- In case of interop, when the ref attribute is used on a custom class component (based on JS classes), the ref object receives the mounted instance of the component as its current (not discussed in this document).
- **You may not use the ref attribute on component functions** because they don’t have instances (we don't expose JS classes in ReScript).

Expand All @@ -83,10 +83,10 @@ This code uses a `React.ref` to store a reference to an `input` DOM node to put

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

let focusInput = () =>
switch textInput.current->Js.Nullable.toOption {
switch textInput.current->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.

no need to convert to option anymore, just pattern-match directly:

switch textInput.current {
| Value(dom) => dom->focusNull | Undefined => ()
}

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

| Some(dom) => dom->focus
| None => ()
}
Expand Down Expand Up @@ -126,7 +126,7 @@ function CustomTextInput(Props) {

A few things happened here, so let's break them down:

- We initialize our `textInput` ref as a `Js.Nullable.null`
- We initialize our `textInput` ref as a `Nullable.null`
- We register our `textInput` ref in our `<input>` element with `ReactDOM.Ref.domRef(textInput)`
- In our `focusInput` function, we need to first verify that our DOM element is set, and then use the `focus` binding to set the focus

Expand All @@ -148,7 +148,7 @@ module MyComp = {

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

// This will **not** work
<MyComp ref={ReactDOM.Ref.domRef(textInput)} />
Expand Down Expand Up @@ -193,15 +193,15 @@ The example below implements a common pattern: using the ref callback to store a

@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 Expand Up @@ -261,7 +261,7 @@ module CustomTextInput = {

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

<CustomTextInput setInputRef/>
Expand Down
Loading