Skip to content

Migrate examples to Core #796

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 3 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion misc_docs/syntax/builtinfunctions_ignore.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The `ignore()` function discards the value of its argument and returns `()`.
```res
mySideEffect()->Promise.catch(handleError)->ignore

Js.Global.setTimeout(myFunc, 1000)->ignore
setTimeout(myFunc, 1000)->ignore
```

```js
Expand Down
2 changes: 1 addition & 1 deletion misc_docs/syntax/decorator_val.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type timeoutID
@val
external setTimeout: (unit => unit, int) => timeoutID = "setTimeout"

let timeoutID = setTimeout(() => Js.log("Hello"), 1000)
let timeoutID = setTimeout(() => Console.log("Hello"), 1000)
```

```js
Expand Down
4 changes: 2 additions & 2 deletions misc_docs/syntax/extension_regular_expression.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ category: "extensionpoints"

```res
let regex = %re("/^hello/")
let result = regex->Js.Re.test_("hello world")
let result = regex->Re.test("hello world")
```

```js
Expand All @@ -26,4 +26,4 @@ var result = regex.test("hello world");

* [Regular Expressions](/docs/manual/latest/primitive-types#regular-expression)
* [Extension Point Attributes](/docs/manual/latest/attribute#extension-point)
* [Js.Re API](/docs/manual/latest/api/js/re)
* [Re API](/docs/manual/latest/api/core/re)
2 changes: 1 addition & 1 deletion misc_docs/syntax/language_async.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let logUserDetails = async (userId: string) => {

await sendAnalytics(`User details have been logged for ${userId}`)

Js.log(`Email address for user ${userId}: ${email}`)
Console.log(`Email address for user ${userId}: ${email}`)
}
```

Expand Down
2 changes: 1 addition & 1 deletion misc_docs/syntax/language_await.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Use the `await` within an `async` function to unwrap a promise value in a seamin
let fetchMessages = async () => {
let message = await queryMessagesApi("message-id-1")

Js.log(message)
Console.log(message)
}
```

Expand Down
6 changes: 3 additions & 3 deletions misc_docs/syntax/language_open.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ In some cases, `open` will cause a "shadow warning" due to existing identifiers
<CodeTab labels={["ReScript", "JS Output"]}>

```res
open Js.Math
open Math
// Use _PI and pow_float from the Js.Math module
let area = radius => _PI *. pow_float(~base=radius, ~exp=2.0)
// Use _PI and pow_float from the Math module
let area = radius => Constants.pi *. pow(radius, ~exp=2.0)
```

```js
Expand Down
6 changes: 3 additions & 3 deletions misc_docs/syntax/language_placeholder.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Placeholders may be used for [ignoring parts of values](/docs/manual/latest/patt

```res
switch person1 {
| Teacher(_) => Js.log("Hi teacher")
| Student(_) => Js.log("Hey student")
| Teacher(_) => Console.log("Hi teacher")
| Student(_) => Console.log("Hey student")
}
```

```js
if (person1.TAG === /* Teacher */ 0) {
if (person1.TAG === "Teacher") {
console.log("Hi teacher");
} else {
console.log("Hey student");
Expand Down
13 changes: 5 additions & 8 deletions misc_docs/syntax/language_switch.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,20 @@ type shape = Circle(float) | Square(float)
let shape = Square(3.0)

let message = switch shape {
| Circle(radius) => "Circle with radius " ++ Js.Float.toString(radius)
| Square(length) => "Square with sides of length " ++ Js.Float.toString(length)
| Circle(radius) => "Circle with radius " ++ Float.toString(radius)
| Square(length) => "Square with sides of length " ++ Float.toString(length)
}
```

```js
var shape = {
TAG: /* Square */ 1,
_0: 3.0,
TAG: "Square",
_0: 3.0
};

var message;

message =
shape.TAG === /* Circle */ 0
? "Circle with radius " + (3.0).toString()
: "Square with sides of length " + (3.0).toString();
message = shape.TAG === "Circle" ? "Circle with radius " + (3.0).toString() : "Square with sides of length " + (3.0).toString();
```

</CodeTab>
Expand Down
17 changes: 9 additions & 8 deletions misc_docs/syntax/operators_pipe.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@ The `->` operator passes a value into the first argument position of a function.

```res
let dieRoll = size => {
Js.Math.random_int(1, size)
Math.Int.random(1, size)
}

let dieRollMessage = (value, name) => {
"Hi " ++ name ++ ", you rolled a " ++ Js.Int.toString(value)
"Hi " ++ name ++ ", you rolled a " ++ Int.toString(value)
}

let message = dieRoll(6)->dieRollMessage("Marshall")
```

```js
function dieRoll(size) {
return Js_math.random_int(1, size);
return Core__Math.Int.random(1, size);
}

function dieRollMessage(value, name) {
return "Hi " + name + ", you rolled a " + value.toString();
}

var message = dieRollMessage(Js_math.random_int(1, 6), "Marshall");
var message = dieRollMessage(dieRoll(6), "Marshall");
```

</CodeTab>
Expand All @@ -46,28 +46,29 @@ You can also explicitly define the argument position of a piped value by using t

```res example
let logMsg = (user: string, datestr: string, msg: string): unit => {
Js.log(`${user}|${datestr}|${msg}`)
Console.log(`${user}|${datestr}|${msg}`)
}

let datestr = "01-01-2021"
let user = "admin"

// Here, we put the result of toUpperCase into the last position
// denoted with an _
Js.String2.toUpperCase("example message")->logMsg(user, datestr, _)
String.toUpperCase("example message")->logMsg(user, datestr, _)
```

```js
function logMsg(user, datestr, msg) {
console.log(user + "|" + datestr + "|" + msg);

}

var datestr = "01-01-2021";

var user = "admin";

logMsg(user, datestr, "example message".toUpperCase());
((function (__x) {
logMsg(user, datestr, __x);
})("example message".toUpperCase()));
Copy link
Member

Choose a reason for hiding this comment

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

This change in the JS output seems weird.

```

</CodeTab>
Expand Down
8 changes: 4 additions & 4 deletions misc_docs/syntax/operators_triangle_pipe.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@ The `|>` operator passes a value to a function as its last argument.

```res
let dieRoll = size => {
Js.Math.random_int(1, size)
Math.Int.random(1, size)
}

let dieRollMessage = (name, value) => {
"Hi " ++ name ++ ", you rolled a " ++ Js.Int.toString(value)
"Hi " ++ name ++ ", you rolled a " ++ Int.toString(value)
}

let message = dieRoll(6) |> dieRollMessage("Jeremy")
```

```js
function dieRoll(size) {
return Js_math.random_int(1, size);
return Core__Math.Int.random(1, size);
}

function dieRollMessage(name, value) {
return "Hi " + name + ", you rolled a " + value.toString();
}

var message = dieRollMessage("Jeremy", Js_math.random_int(1, 6));
var message = dieRollMessage("Jeremy", dieRoll(6));
Copy link
Member

Choose a reason for hiding this comment

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

Here it seems we lost some inlining in v11 / uncurried.

```

</CodeTab>
Expand Down
2 changes: 1 addition & 1 deletion misc_docs/syntax/specialvalues_file.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ category: "specialvalues"

```res example
// testmodule.res
__FILE__->Js.log
__FILE__->Console.log
```

```js
Expand Down
2 changes: 1 addition & 1 deletion misc_docs/syntax/specialvalues_line.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ category: "specialvalues"
```res example
// Line 1
// Line 2
__LINE__->Js.log
__LINE__->Console.log
```

```js
Expand Down
13 changes: 10 additions & 3 deletions misc_docs/syntax/specialvalues_line_of.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,23 @@ category: "specialvalues"
let f = () => None
let (line, f') = __LINE_OF__(f)

line->Js.log
f'->Js.log
line->Console.log
f'->Console.log

```

```js
function f(param) {}
function f() {

}

console.log(2);

console.log(f);

var line = 2;

var f$p = f;
```

</CodeTab>
2 changes: 1 addition & 1 deletion misc_docs/syntax/specialvalues_loc.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The string format is `"File %S, line %d, characters %d-%d"`
<CodeTab labels={["ReScript", "JS Output"]}>

```res example
__LOC__->Js.log
__LOC__->Console.log
```

```js
Expand Down
9 changes: 6 additions & 3 deletions misc_docs/syntax/specialvalues_loc_of.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@ category: "specialvalues"
let f = () => None
let (loc, f') = __LOC_OF__(f)
loc->Js.log
f'->Js.log
loc->Console.log
f'->Console.log
```

```js
function f(param) {}
function f() {

}

var loc = "File \"testmodule.res\", line 2, characters 27-28";

console.log(loc);
console.log(f);
var f$p = f;
```

</CodeTab>
2 changes: 1 addition & 1 deletion misc_docs/syntax/specialvalues_module.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ category: "specialvalues"
<CodeTab labels={["ReScript", "JS Output"]}>

```res example
__MODULE__->Js.log
__MODULE__->Console.log
```

```js
Expand Down
8 changes: 4 additions & 4 deletions misc_docs/syntax/specialvalues_pos.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ It basically provides the same information as `__LOC__`, but separated into mult
```res example
let (fileName, lineNumber, columnNumberStart, columnNumberEnd) = __POS__

fileName->Js.log
lineNumber->Js.log
columnNumberStart->Js.log
columnNumberEnd->Js.log
fileName->Console.log
lineNumber->Console.log
columnNumberStart->Console.log
columnNumberEnd->Console.log
```

```js
Expand Down
5 changes: 3 additions & 2 deletions misc_docs/syntax/specialvalues_pos_of.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ It basically provides the same information as `__LOC_OF__`, but separated into m
let f = () => None
let (pos, f') = __POS_OF__(f)

pos->Js.log
f'->Js.log
pos->Console.log
f'->Console.log
```

```js
Expand All @@ -35,6 +35,7 @@ var pos = [

console.log(pos);
console.log(f);
var f$p = f;
```

</CodeTab>
4 changes: 2 additions & 2 deletions pages/docs/gentype/latest/supported-types.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ So the option type is exported to JS type `null` or `undefined` or `number`.

## Nullables

ReScript values of type e.g. `Js.Nullable.t<int>`, such as `Js.Nullable.null`, `Js.Nullable.undefined`, `Js.Nullable.return(0)`, `Js.Nullable.return(1)`, `Js.Nullable.return(2)`, are exported to JS values `null`, `undefined`, `0`, `1`, `2`.
ReScript values of type e.g. `Nullable.t<int>`, such as `Nullable.null`, `Nullable.undefined`, `Nullable.make(0)`, `Nullable.make(1)`, `Nullable.make(2)`, are exported to JS values `null`, `undefined`, `0`, `1`, `2`.
The JS values are identical: there is no conversion unless the argument type needs conversion.

## Records
Expand Down Expand Up @@ -191,5 +191,5 @@ const none = <T1>(a: T1): ?T1 => OptionBS.none;

## Promises

Values of type `Js.Promise.t<arg>` are exported to JS promises of type `Promise<argJS>` where `argJS` is the JS type corresponding to `arg`.
Values of type `Promise.t<arg>` are exported to JS promises of type `Promise<argJS>` where `argJS` is the JS type corresponding to `arg`.
If a conversion for the argument is required, the conversion functions are chained via `.then(promise => ...)`.
6 changes: 3 additions & 3 deletions pages/docs/gentype/latest/usage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ To export a function `callback` to JS:

```res
@genType
let callback = _ => Js.log("Clicked");
let callback = _ => Console.log("Clicked");
```

To rename the function and export it as `CB` on the JS side, use

```res
@genType
@genType.as("CB")
let callback = _ => Js.log("Clicked");
let callback = _ => Console.log("Clicked");
```

or the more compact

```res
@genType("CB")
let callback = _ => Js.log("Clicked");
let callback = _ => Console.log("Clicked");
```


Expand Down
4 changes: 2 additions & 2 deletions pages/docs/manual/latest/array-and-list.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ You'd use list for its resizability, its fast prepend (adding at the head), and

Do **not** use list if you need to randomly access an item or insert at non-head position. Your code would end up obtuse and/or slow.

The standard lib provides a [List module](api/belt/list).
The standard lib provides a [List module](api/core/list).

#### Immutable Prepend

Expand Down Expand Up @@ -133,7 +133,7 @@ var anotherList = {
let message =
switch myList {
| list{} => "This list is empty"
| list{a, ...rest} => "The head of the list is the string " ++ Js.Int.toString(a)
| list{a, ...rest} => "The head of the list is the string " ++ Int.toString(a)
}
```
```js
Expand Down
Loading