Skip to content

Commit 348d0b2

Browse files
Merge pull request #796 from aspeddro/rescript-core-docs
Migrate examples to Core
2 parents 86a349f + b83ebc8 commit 348d0b2

38 files changed

+161
-156
lines changed

misc_docs/syntax/builtinfunctions_ignore.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The `ignore()` function discards the value of its argument and returns `()`.
1515
```res
1616
mySideEffect()->Promise.catch(handleError)->ignore
1717
18-
Js.Global.setTimeout(myFunc, 1000)->ignore
18+
setTimeout(myFunc, 1000)->ignore
1919
```
2020

2121
```js

misc_docs/syntax/decorator_val.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type timeoutID
1818
@val
1919
external setTimeout: (unit => unit, int) => timeoutID = "setTimeout"
2020
21-
let timeoutID = setTimeout(() => Js.log("Hello"), 1000)
21+
let timeoutID = setTimeout(() => Console.log("Hello"), 1000)
2222
```
2323

2424
```js

misc_docs/syntax/extension_regular_expression.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ category: "extensionpoints"
1212

1313
```res
1414
let regex = %re("/^hello/")
15-
let result = regex->Js.Re.test_("hello world")
15+
let result = regex->Re.test("hello world")
1616
```
1717

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

2727
* [Regular Expressions](/docs/manual/latest/primitive-types#regular-expression)
2828
* [Extension Point Attributes](/docs/manual/latest/attribute#extension-point)
29-
* [Js.Re API](/docs/manual/latest/api/js/re)
29+
* [Re API](/docs/manual/latest/api/core/re)

misc_docs/syntax/language_async.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ let logUserDetails = async (userId: string) => {
2626
2727
await sendAnalytics(`User details have been logged for ${userId}`)
2828
29-
Js.log(`Email address for user ${userId}: ${email}`)
29+
Console.log(`Email address for user ${userId}: ${email}`)
3030
}
3131
```
3232

misc_docs/syntax/language_await.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Use the `await` within an `async` function to unwrap a promise value in a seamin
2020
let fetchMessages = async () => {
2121
let message = await queryMessagesApi("message-id-1")
2222
23-
Js.log(message)
23+
Console.log(message)
2424
}
2525
```
2626

misc_docs/syntax/language_open.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ In some cases, `open` will cause a "shadow warning" due to existing identifiers
1515
<CodeTab labels={["ReScript", "JS Output"]}>
1616

1717
```res
18-
open Js.Math
18+
open Math
1919
20-
// Use _PI and pow_float from the Js.Math module
21-
let area = radius => _PI *. pow_float(~base=radius, ~exp=2.0)
20+
// Use _PI and pow_float from the Math module
21+
let area = radius => Constants.pi *. pow(radius, ~exp=2.0)
2222
```
2323

2424
```js

misc_docs/syntax/language_placeholder.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ Placeholders may be used for [ignoring parts of values](/docs/manual/latest/patt
1414

1515
```res
1616
switch person1 {
17-
| Teacher(_) => Js.log("Hi teacher")
18-
| Student(_) => Js.log("Hey student")
17+
| Teacher(_) => Console.log("Hi teacher")
18+
| Student(_) => Console.log("Hey student")
1919
}
2020
```
2121

2222
```js
23-
if (person1.TAG === /* Teacher */ 0) {
23+
if (person1.TAG === "Teacher") {
2424
console.log("Hi teacher");
2525
} else {
2626
console.log("Hey student");

misc_docs/syntax/language_switch.mdx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,20 @@ type shape = Circle(float) | Square(float)
1818
let shape = Square(3.0)
1919
2020
let message = switch shape {
21-
| Circle(radius) => "Circle with radius " ++ Js.Float.toString(radius)
22-
| Square(length) => "Square with sides of length " ++ Js.Float.toString(length)
21+
| Circle(radius) => "Circle with radius " ++ Float.toString(radius)
22+
| Square(length) => "Square with sides of length " ++ Float.toString(length)
2323
}
2424
```
2525

2626
```js
2727
var shape = {
28-
TAG: /* Square */ 1,
29-
_0: 3.0,
28+
TAG: "Square",
29+
_0: 3.0
3030
};
3131

3232
var message;
3333

34-
message =
35-
shape.TAG === /* Circle */ 0
36-
? "Circle with radius " + (3.0).toString()
37-
: "Square with sides of length " + (3.0).toString();
34+
message = shape.TAG === "Circle" ? "Circle with radius " + (3.0).toString() : "Square with sides of length " + (3.0).toString();
3835
```
3936

4037
</CodeTab>

misc_docs/syntax/operators_pipe.mdx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,26 @@ The `->` operator passes a value into the first argument position of a function.
1414

1515
```res
1616
let dieRoll = size => {
17-
Js.Math.random_int(1, size)
17+
Math.Int.random(1, size)
1818
}
1919
2020
let dieRollMessage = (value, name) => {
21-
"Hi " ++ name ++ ", you rolled a " ++ Js.Int.toString(value)
21+
"Hi " ++ name ++ ", you rolled a " ++ Int.toString(value)
2222
}
2323
2424
let message = dieRoll(6)->dieRollMessage("Marshall")
2525
```
2626

2727
```js
2828
function dieRoll(size) {
29-
return Js_math.random_int(1, size);
29+
return Core__Math.Int.random(1, size);
3030
}
3131

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

36-
var message = dieRollMessage(Js_math.random_int(1, 6), "Marshall");
36+
var message = dieRollMessage(dieRoll(6), "Marshall");
3737
```
3838

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

4747
```res example
4848
let logMsg = (user: string, datestr: string, msg: string): unit => {
49-
Js.log(`${user}|${datestr}|${msg}`)
49+
Console.log(`${user}|${datestr}|${msg}`)
5050
}
5151
5252
let datestr = "01-01-2021"
5353
let user = "admin"
5454
5555
// Here, we put the result of toUpperCase into the last position
5656
// denoted with an _
57-
Js.String2.toUpperCase("example message")->logMsg(user, datestr, _)
57+
String.toUpperCase("example message")->logMsg(user, datestr, _)
5858
```
5959

6060
```js
6161
function logMsg(user, datestr, msg) {
6262
console.log(user + "|" + datestr + "|" + msg);
63-
6463
}
6564

6665
var datestr = "01-01-2021";
6766

6867
var user = "admin";
6968

70-
logMsg(user, datestr, "example message".toUpperCase());
69+
((function (__x) {
70+
logMsg(user, datestr, __x);
71+
})("example message".toUpperCase()));
7172
```
7273

7374
</CodeTab>

misc_docs/syntax/operators_triangle_pipe.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,26 @@ The `|>` operator passes a value to a function as its last argument.
1616

1717
```res
1818
let dieRoll = size => {
19-
Js.Math.random_int(1, size)
19+
Math.Int.random(1, size)
2020
}
2121
2222
let dieRollMessage = (name, value) => {
23-
"Hi " ++ name ++ ", you rolled a " ++ Js.Int.toString(value)
23+
"Hi " ++ name ++ ", you rolled a " ++ Int.toString(value)
2424
}
2525
2626
let message = dieRoll(6) |> dieRollMessage("Jeremy")
2727
```
2828

2929
```js
3030
function dieRoll(size) {
31-
return Js_math.random_int(1, size);
31+
return Core__Math.Int.random(1, size);
3232
}
3333

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

38-
var message = dieRollMessage("Jeremy", Js_math.random_int(1, 6));
38+
var message = dieRollMessage("Jeremy", dieRoll(6));
3939
```
4040

4141
</CodeTab>

0 commit comments

Comments
 (0)