Skip to content

Commit

Permalink
Update reason snippets after 3.13 (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
jchavarri authored Dec 3, 2024
1 parent 0613b8a commit e8e5376
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 14 deletions.
76 changes: 64 additions & 12 deletions docs/communicate-with-javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,10 @@ type t = {
bar: string,
};
let value = {foo: 7, bar: "baz"};
let value = {
foo: 7,
bar: "baz",
};
```

And its JavaScript generated code:
Expand Down Expand Up @@ -1185,7 +1188,10 @@ let john = [%mel.obj { name = "john"; age = 99 }]
let t = john##name
```
```reasonml
let john = {"name": "john", "age": 99};
let john = {
"name": "john",
"age": 99,
};
let t = john##name;
```

Expand Down Expand Up @@ -1218,8 +1224,16 @@ let two = name_extended [%mel.obj { name = "jane"; address = "1 infinite loop" }
```reasonml
let name_extended = obj => obj##name ++ " wayne";
let one = name_extended({"name": "john", "age": 99});
let two = name_extended({"name": "jane", "address": "1 infinite loop"});
let one =
name_extended({
"name": "john",
"age": 99,
});
let two =
name_extended({
"name": "jane",
"address": "1 infinite loop",
});
```

To read more about objects and polymorphism we recommend checking the [OCaml
Expand Down Expand Up @@ -2018,7 +2032,14 @@ let _ = padLeft "Hello World" (`Str "Message from Melange: ")
```
```reasonml
external padLeft:
(string, [@mel.unwrap] [ | `Str(string) | `Int(int)]) => string =
(
string,
[@mel.unwrap] [
| `Str(string)
| `Int(int)
]
) =>
string =
"padLeft";
let _ = padLeft("Hello World", `Int(4));
Expand Down Expand Up @@ -2063,7 +2084,14 @@ let _ = read_file_sync ~name:"xx.txt" `ascii
```reasonml
[@mel.module "fs"]
external read_file_sync:
(~name: string, [@mel.string] [ | `utf8 | `ascii]) => string =
(
~name: string,
[@mel.string] [
| `utf8
| `ascii
]
) =>
string =
"readFileSync";
let _ = read_file_sync(~name="xx.txt", `ascii);
Expand Down Expand Up @@ -2148,7 +2176,15 @@ let value = test_int_type `on_open
```
```reasonml
external test_int_type:
([@mel.int] [ | `on_closed | [@mel.as 20] `on_open | `in_bin]) => int =
(
[@mel.int]
[
| `on_closed
| [@mel.as 20] `on_open
| `in_bin
]
) =>
int =
"testIntType";
let value = test_int_type(`on_open);
Expand Down Expand Up @@ -2189,7 +2225,10 @@ type readline;
external on:
(
readline,
[@mel.string] [ | `close(unit => unit) | `line(string => unit)]
[@mel.string] [
| `close(unit => unit)
| `line(string => unit)
]
) =>
readline =
"on";
Expand Down Expand Up @@ -2753,7 +2792,11 @@ type action =
```
```reasonml
[@deriving jsConverter]
type action = [ | `Click | [@mel.as "submit"] `Submit | `Cancel];
type action = [
| `Click
| [@mel.as "submit"] `Submit
| `Cancel
];
```

Akin to the variant example, the following two functions will be generated:
Expand Down Expand Up @@ -3465,7 +3508,10 @@ literal directly:
let person = [%mel.obj { id = 1; name = "Alice" }]
```
```reasonml
let person = {"id": 1, "name": "Alice"};
let person = {
"id": 1,
"name": "Alice",
};
```

See the [Using `Js.t` objects](#using-jst-objects) section for more information.
Expand All @@ -3482,7 +3528,10 @@ type person = {
id: int,
name: string,
};
let person = {id: 1, name: "Alice"};
let person = {
id: 1,
name: "Alice",
};
```

See the [Using OCaml records](#using-ocaml-records) section for more
Expand Down Expand Up @@ -3545,7 +3594,10 @@ type person = {
name: string,
};
let person = {id: 1, name: "Alice"};
let person = {
id: 1,
name: "Alice",
};
let {id, name} = person;
```

Expand Down
2 changes: 1 addition & 1 deletion documentation-site.opam
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ bug-reports: "https://github.com/melange-re/melange-re.github.io"
depends: [
"ocaml"
"dune" {>= "3.8.0"}
"reason" {>= "3.12.0" & < "3.13.0"}
"reason" {>= "3.13.0"}
"reason-react"
"reason-react-ppx"
"ocamlformat"
Expand Down
2 changes: 1 addition & 1 deletion playground/src/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function Sidebar({ onExampleClick }) {
</span>
<span className="Version">
<span className="Text-xs">{"Reason"}</span>
<span className="Text-xs Number">{"3.12.0"}</span>
<span className="Text-xs Number">{"3.14.0"}</span>
</span>
<span className="Version">
<span className="Text-xs">{"ReasonReact"}</span>
Expand Down

0 comments on commit e8e5376

Please sign in to comment.