Skip to content

Commit

Permalink
Definee constrains for Melange v2 (#785)
Browse files Browse the repository at this point in the history
  • Loading branch information
davesnx authored Sep 19, 2023
1 parent cd5f4ff commit bd5237e
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 23 deletions.
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,12 @@ format-check: ## Checks if format is correct

.PHONY: install
install: ## Update the package dependencies when new deps are added to dune-project
@opam pin add -y melange.dev --dev-repo
@opam pin add -y reason.dev --dev-repo
@opam install . --deps-only --with-test
@npm install

.PHONY: init
create-switch: ## Create a local opam switch
@opam switch create . 5.1.0~alpha2 --no-install
@opam switch create . 5.1.0 --no-install

.PHONY: init
init: create-switch install ## Create a local opam switch, install deps
6 changes: 3 additions & 3 deletions docs/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ let make = (Props) => {
};
```

It has added a new function called `makeProps` which uses [`[@bs.obj]`](https://melange.re/v1.0.0/communicate-with-javascript/#using-jst-objects) to create your props object. This function gets compiled away by Melange and will be replaced by object literals when used.
It has added a new function called `makeProps` which uses [`[@bs.obj]`](https://melange.re/v2.0.0/communicate-with-javascript/#using-jst-objects) to create your props object. This function gets compiled away by Melange and will be replaced by object literals when used.

### A note on `children`

Expand Down Expand Up @@ -113,7 +113,7 @@ Reason also always opts for the safest form of a given hook as well. So `React.u

## Hand-writing components

You don't need to use the `[@react.component]` declaration to write components. Instead you can write a pair of `foo` and `fooProps` functions such that `type fooProps: 'a => props and foo: props => React.element` and these will always work as React components! This works with your own version of [`[@bs.obj]`](https://melange.re/v1.0.0/communicate-with-javascript/#using-jst-objects), [`[bs.deriving abstract]`](https://melange.re/v1.0.0/communicate-with-javascript/#convert-records-into-abstract-types), or any other function that takes named args and returns a single props structure.
You don't need to use the `[@react.component]` declaration to write components. Instead you can write a pair of `foo` and `fooProps` functions such that `type fooProps: 'a => props and foo: props => React.element` and these will always work as React components! This works with your own version of [`[@bs.obj]`](https://melange.re/v2.0.0/communicate-with-javascript/#using-jst-objects), [`[bs.deriving abstract]`](https://melange.re/v2.0.0/communicate-with-javascript/#convert-records-into-abstract-types), or any other function that takes named args and returns a single props structure.

## Interop

Expand Down Expand Up @@ -148,7 +148,7 @@ external makeProps: (~name: 'name, ~key: string=?, unit) => {. "name": 'name} =
external make: ({. "name": string}) => React.element = "default";
```

**Note on `default`:** to understand what `default` means, see [the Melange docs on ES6](https://melange.re/v1.0.0/communicate-with-javascript/#default-es6-values).
**Note on `default`:** to understand what `default` means, see [the Melange docs on ES6](https://melange.re/v2.0.0/communicate-with-javascript/#default-es6-values).

## Component Naming

Expand Down
2 changes: 1 addition & 1 deletion docs/element-type-is-invalid.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This likely means that:
- The JS component uses ES6 default export (`export default MyComponent`) (or, you forgot to export the component altogether!).
- You're using Babel/Webpack to compile those ES6 modules.

This is a common mistake. Please see Melange's [Import an ES6 Default Value](https://melange.re/v1.0.0/communicate-with-javascript/#default-es6-values). Aka, instead of:
This is a common mistake. Please see Melange's [Import an ES6 Default Value](https://melange.re/v2.0.0/communicate-with-javascript/#default-es6-values). Aka, instead of:

```reason
[@bs.module] external myJSReactClass: ReasonReact.reactClass = "./myJSReactClass";
Expand Down
2 changes: 1 addition & 1 deletion docs/event.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ReactEvent module contains all event types as submodules, e.g. `ReactEvent.Form`

You can access their properties using the `ReactEvent.{{EventName}}.{{property}}` method. For example, to access the `target` property of a `ReactEvent.Form.t` event, you would use `ReactEvent.Form.target`.

Since `target` is a JavaScript Object, those are typed as [`Js.t`](https://melange.re/v1.0.0/communicate-with-javascript/#using-jst-objects). If you're accessing fields on an object, like `event.target.value`, you'd use [Melange's `##` object access FFI](https://melange.re/v1.0.0/communicate-with-javascript/#using-jst-objects):
Since `target` is a JavaScript Object, those are typed as [`Js.t`](https://melange.re/v2.0.0/communicate-with-javascript/#using-jst-objects). If you're accessing fields on an object, like `event.target.value`, you'd use [Melange's `##` object access FFI](https://melange.re/v2.0.0/communicate-with-javascript/#using-jst-objects):

```reason
ReactEvent.Form.target(event)##value;
Expand Down
8 changes: 4 additions & 4 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ ReasonReact is built to work with [Melange](https://melange.re/) and [Reason](ht

If you want to build a new app or a new website with ReasonReact and Melange, we recommend to use a package manager such as [opam](https://opam.ocaml.org/) to download and install the required dependencies.

There are other alternatives available, such as [esy](https://esy.sh/) or [nix](https://nixos.org/). See [Melange documentation](https://melange.re/v1.0.0/getting-started/#alternative-package-managers-experimental) for details.
There are other alternatives available, such as [esy](https://esy.sh/) or [nix](https://nixos.org/). See [Melange documentation](https://melange.re/v2.0.0/getting-started/#alternative-package-managers-experimental) for details.

#### Requirements

- [melange](https://opam.ocaml.org/packages/melange) v1.0.0 or higher
- [melange](https://opam.ocaml.org/packages/melange) v2.0.0 or higher
- [dune](https://opam.ocaml.org/packages/dune/) v3.8.0 or higher

## Melange

Melange is the toolchain that compiles Reason and OCaml to JavaScript. It integrates with dune to provide a seamless experience for building and running your project.

Follow the getting started guide on [Melange's documentation](https://melange.re/v1.0.0/getting-started/) to continue.
Follow the getting started guide on [Melange's documentation](https://melange.re/v2.0.0/getting-started/) to continue.

## Editor Setup

Since Reason is an alternative syntax for OCaml, we integrate seamlessly into the official OCaml editor toolchain. Following the recommendation from [Melange's documentation](https://melange.re/v1.0.0/getting-started/#editor-integration).
Since Reason is an alternative syntax for OCaml, we integrate seamlessly into the official OCaml editor toolchain. Following the recommendation from [Melange's documentation](https://melange.re/v2.0.0/getting-started/#editor-integration).

- For VSCode, we recommend using the [vscode-ocaml-platform](https://github.com/ocamllabs/vscode-ocaml-platform) plugin
- For other editors (Emacs and Vim), we recommend using a language server client plugin of your choice, and pairing it with [ocaml-lsp](https://github.com/ocaml/ocaml-lsp).
Expand Down
2 changes: 1 addition & 1 deletion docs/intro-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if (root != null) {

### Using Greeting in an existing JavaScript/Typescript application

It's easy to import a ReasonReact component into your existing app. After being transpiled to JS, all Reason components will have `.js` as extension by default and export a function component called `make`. You can change it with [module_systems](https://melange.re/v1.0.0/build-system/#commonjs-or-es6-modules) field inside a [`melange.emit` stanza](https://dune.readthedocs.io/en/stable/melange.html#melange-emit).
It's easy to import a ReasonReact component into your existing app. After being transpiled to JS, all Reason components will have `.js` as extension by default and export a function component called `make`. You can change it with [module_systems](https://melange.re/v2.0.0/build-system/#commonjs-or-es6-modules) field inside a [`melange.emit` stanza](https://dune.readthedocs.io/en/stable/melange.html#melange-emit).

```js
/* file: App.js */
Expand Down
8 changes: 4 additions & 4 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
"ReasonReact helps you use Reason to build React components with deeply integrated, strong, static type safety.\n\nIt is designed and built by people using Reason and React in large, mission critical production React codebases.")
(depends
(ocaml
(>= 4.13.0))
(and (>= 5.1.0) (< 5.2.0)))
(melange
(>= 1.0.0))
(>= 2.0.0))
(reason-react-ppx
(= :version))
(reason
Expand All @@ -56,8 +56,8 @@
(synopsis "React.js JSX PPX")
(description "ReasonReact JSX PPX")
(depends
(ocaml
(>= 4.13.0))
(ocaml
(and (>= 5.1.0) (< 5.2.0)))
(reason
(>= 3.10.0))
(ppxlib
Expand Down
2 changes: 1 addition & 1 deletion reason-react-ppx.opam
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ doc: "https://reasonml.github.io/reason-react"
bug-reports: "https://github.com/reasonml/reason-react/issues"
depends: [
"dune" {>= "3.9"}
"ocaml" {>= "4.13.0"}
"ocaml" {>= "5.1.0" & < "5.2.0"}
"reason" {>= "3.10.0"}
"ppxlib" {>= "0.28.0"}
"merlin" {= "4.9-501preview" & with-test}
Expand Down
4 changes: 2 additions & 2 deletions reason-react.opam
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ doc: "https://reasonml.github.io/reason-react"
bug-reports: "https://github.com/reasonml/reason-react/issues"
depends: [
"dune" {>= "3.9"}
"ocaml" {>= "4.13.0"}
"melange" {>= "1.0.0"}
"ocaml" {>= "5.1.0" & < "5.2.0"}
"melange" {>= "2.0.0"}
"reason-react-ppx" {= version}
"reason" {>= "3.10.0"}
"ocaml-lsp-server" {with-test}
Expand Down
4 changes: 2 additions & 2 deletions website/blog/2023-06-11-reborn.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ Today, we are happy to announce that ReasonReact is back and will be maintained

## What's changing?

We released ReasonReact to the [opam repository](https://ocaml.org/p/reason-react/latest). In the Melange docs, we document [how to depend](https://melange.re/v1.0.0/package-management/) on packages in opam.
We released ReasonReact to the [opam repository](https://ocaml.org/p/reason-react/latest). In the Melange docs, we document [how to depend](https://melange.re/v2.0.0/package-management/) on packages in opam.

We updated the documentation to reflect these new changes and we will continue to improve it over time.

## Adopting ReasonReact

To use ReasonReact, you must be using Melange. [Get started here](https://melange.re/v1.0.0/getting-started/).
To use ReasonReact, you must be using Melange. [Get started here](https://melange.re/v2.0.0/getting-started/).

Next:

Expand Down
2 changes: 1 addition & 1 deletion website/blog/2023-09-13-reason-react-ppx.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Take a look at [reasonml/reason-react/releases/tag/0.12.0](https://github.com/re

## Updating to latest

ReasonReact works best with Melange. [Get started here](https://melange.re/v1.0.0/getting-started/).
ReasonReact works best with Melange. [Get started here](https://melange.re/v2.0.0/getting-started/).

Next:

Expand Down

0 comments on commit bd5237e

Please sign in to comment.