Skip to content

Commit 348d0b2

Browse files
Merge pull request rescript-lang#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>

misc_docs/syntax/specialvalues_file.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ category: "specialvalues"
1212

1313
```res example
1414
// testmodule.res
15-
__FILE__->Js.log
15+
__FILE__->Console.log
1616
```
1717

1818
```js

misc_docs/syntax/specialvalues_line.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ category: "specialvalues"
1313
```res example
1414
// Line 1
1515
// Line 2
16-
__LINE__->Js.log
16+
__LINE__->Console.log
1717
```
1818

1919
```js

misc_docs/syntax/specialvalues_line_of.mdx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,23 @@ category: "specialvalues"
1616
let f = () => None
1717
let (line, f') = __LINE_OF__(f)
1818
19-
line->Js.log
20-
f'->Js.log
19+
line->Console.log
20+
f'->Console.log
2121
2222
```
2323

2424
```js
25-
function f(param) {}
25+
function f() {
26+
27+
}
2628

2729
console.log(2);
30+
2831
console.log(f);
32+
33+
var line = 2;
34+
35+
var f$p = f;
2936
```
3037

3138
</CodeTab>

misc_docs/syntax/specialvalues_loc.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The string format is `"File %S, line %d, characters %d-%d"`
1212
<CodeTab labels={["ReScript", "JS Output"]}>
1313

1414
```res example
15-
__LOC__->Js.log
15+
__LOC__->Console.log
1616
```
1717

1818
```js

misc_docs/syntax/specialvalues_loc_of.mdx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,20 @@ category: "specialvalues"
1616
let f = () => None
1717
let (loc, f') = __LOC_OF__(f)
1818
19-
loc->Js.log
20-
f'->Js.log
19+
loc->Console.log
20+
f'->Console.log
2121
```
2222

2323
```js
24-
function f(param) {}
24+
function f() {
25+
26+
}
2527

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

2830
console.log(loc);
2931
console.log(f);
32+
var f$p = f;
3033
```
3134

3235
</CodeTab>

misc_docs/syntax/specialvalues_module.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ category: "specialvalues"
1111
<CodeTab labels={["ReScript", "JS Output"]}>
1212

1313
```res example
14-
__MODULE__->Js.log
14+
__MODULE__->Console.log
1515
```
1616

1717
```js

misc_docs/syntax/specialvalues_pos.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ It basically provides the same information as `__LOC__`, but separated into mult
1515
```res example
1616
let (fileName, lineNumber, columnNumberStart, columnNumberEnd) = __POS__
1717
18-
fileName->Js.log
19-
lineNumber->Js.log
20-
columnNumberStart->Js.log
21-
columnNumberEnd->Js.log
18+
fileName->Console.log
19+
lineNumber->Console.log
20+
columnNumberStart->Console.log
21+
columnNumberEnd->Console.log
2222
```
2323

2424
```js

misc_docs/syntax/specialvalues_pos_of.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ It basically provides the same information as `__LOC_OF__`, but separated into m
1919
let f = () => None
2020
let (pos, f') = __POS_OF__(f)
2121
22-
pos->Js.log
23-
f'->Js.log
22+
pos->Console.log
23+
f'->Console.log
2424
```
2525

2626
```js
@@ -35,6 +35,7 @@ var pos = [
3535

3636
console.log(pos);
3737
console.log(f);
38+
var f$p = f;
3839
```
3940

4041
</CodeTab>

pages/docs/gentype/latest/supported-types.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ So the option type is exported to JS type `null` or `undefined` or `number`.
3232

3333
## Nullables
3434

35-
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`.
35+
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`.
3636
The JS values are identical: there is no conversion unless the argument type needs conversion.
3737

3838
## Records
@@ -191,5 +191,5 @@ const none = <T1>(a: T1): ?T1 => OptionBS.none;
191191
192192
## Promises
193193
194-
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`.
194+
Values of type `Promise.t<arg>` are exported to JS promises of type `Promise<argJS>` where `argJS` is the JS type corresponding to `arg`.
195195
If a conversion for the argument is required, the conversion functions are chained via `.then(promise => ...)`.

pages/docs/gentype/latest/usage.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,22 @@ To export a function `callback` to JS:
3232

3333
```res
3434
@genType
35-
let callback = _ => Js.log("Clicked");
35+
let callback = _ => Console.log("Clicked");
3636
```
3737

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

4040
```res
4141
@genType
4242
@genType.as("CB")
43-
let callback = _ => Js.log("Clicked");
43+
let callback = _ => Console.log("Clicked");
4444
```
4545

4646
or the more compact
4747

4848
```res
4949
@genType("CB")
50-
let callback = _ => Js.log("Clicked");
50+
let callback = _ => Console.log("Clicked");
5151
```
5252

5353

pages/docs/manual/latest/array-and-list.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ You'd use list for its resizability, its fast prepend (adding at the head), and
8787

8888
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.
8989

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

9292
#### Immutable Prepend
9393

@@ -133,7 +133,7 @@ var anotherList = {
133133
let message =
134134
switch myList {
135135
| list{} => "This list is empty"
136-
| list{a, ...rest} => "The head of the list is the string " ++ Js.Int.toString(a)
136+
| list{a, ...rest} => "The head of the list is the string " ++ Int.toString(a)
137137
}
138138
```
139139
```js

0 commit comments

Comments
 (0)