Skip to content

Commit 7f3687c

Browse files
committed
Remove bs. prefix
1 parent 1610ee9 commit 7f3687c

12 files changed

+198
-198
lines changed

pages/docs/manual/latest/attribute.mdx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Like many other languages, ReScript allows annotating a piece of code to express
1111
<CodeTab labels={["ReScript", "JS Output"]}>
1212

1313
```res
14-
@bs.inline
14+
@inline
1515
let mode = "dev"
1616
1717
let mode2 = mode
@@ -22,7 +22,7 @@ var mode2 = "dev";
2222

2323
</CodeTab>
2424

25-
The `@bs.inline` annotation tells `mode`'s value to be inlined into its usage sites (see output). We call such annotation "attribute" (or "decorator" in JavaScript).
25+
The `@inline` annotation tells `mode`'s value to be inlined into its usage sites (see output). We call such annotation "attribute" (or "decorator" in JavaScript).
2626

2727
An attribute starts with `@` and goes before the item it annotates. In the above example, it's hooked onto the let binding.
2828

@@ -39,11 +39,11 @@ You can put an attribute almost anywhere. You can even add extra data to them by
3939
@unboxed
4040
type a = Name(string)
4141
42-
@bs.val external message: string = "message"
42+
@val external message: string = "message"
4343
4444
type student = {
4545
age: int,
46-
@bs.as("aria-label") ariaLabel: string,
46+
@as("aria-label") ariaLabel: string,
4747
}
4848
4949
@deprecated
@@ -59,8 +59,8 @@ let customTriple = foo => foo * 3
5959

6060
1. `@@warning("-27")` is a standalone attribute that annotates the entire file. Those attributes start with `@@`. Here, it carries the data `"-27"`.
6161
2. `@unboxed` annotates the type definition.
62-
3. `@bs.val` annotates the `external` statement.
63-
4. `@bs.as("aria-label")` annotates the `ariaLabel` record field.
62+
3. `@val` annotates the `external` statement.
63+
4. `@as("aria-label")` annotates the `ariaLabel` record field.
6464
5. `@deprecated` annotates the `customDouble` expression. This shows a warning while compiling telling consumers to not rely on this method long-term.
6565
6. `@deprecated("Use SomeOther.customTriple instead")` annotates the `customTriple` expression with a string to describe the reason for deprecation.
6666

pages/docs/manual/latest/bind-to-global-js-values.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Some JS values, like `setTimeout`, live in the global scope. You can bind to the
1313
<CodeTab labels={["ReScript", "JS Output"]}>
1414

1515
```res example
16-
@bs.val external setTimeout: (unit => unit, int) => float = "setTimeout"
17-
@bs.val external clearTimeout: float => unit = "clearTimeout"
16+
@val external setTimeout: (unit => unit, int) => float = "setTimeout"
17+
@val external clearTimeout: float => unit = "clearTimeout"
1818
```
1919
```js
2020
// Empty output
@@ -40,8 +40,8 @@ We're in a language with a great type system now! Let's leverage a popular featu
4040

4141
```res example
4242
type timerId
43-
@bs.val external setTimeout: (unit => unit, int) => timerId = "setTimeout"
44-
@bs.val external clearTimeout: timerId => unit = "clearTimeout"
43+
@val external setTimeout: (unit => unit, int) => timerId = "setTimeout"
44+
@val external clearTimeout: timerId => unit = "clearTimeout"
4545
4646
let id = setTimeout(() => Js.log("hello"), 100)
4747
clearTimeout(id)
@@ -62,12 +62,12 @@ Since `external`s are inlined, we end up with JS output as readable as hand-writ
6262

6363
## Global Modules
6464

65-
If you want to bind to a value inside a global module, e.g. `Math.random`, attach a `bs.scope` to your `bs.val` external:
65+
If you want to bind to a value inside a global module, e.g. `Math.random`, attach a `scope` to your `val` external:
6666

6767
<CodeTab labels={["ReScript", "JS Output"]}>
6868

6969
```res example
70-
@bs.scope("Math") @bs.val external random: unit => float = "random"
70+
@scope("Math") @val external random: unit => float = "random"
7171
let someNumber = random()
7272
```
7373
```js
@@ -76,12 +76,12 @@ var someNumber = Math.random();
7676

7777
</CodeTab>
7878

79-
you can bind to an arbitrarily deep object by passing a tuple to `bs.scope`:
79+
you can bind to an arbitrarily deep object by passing a tuple to `scope`:
8080

8181
<CodeTab labels={["ReScript", "JS Output"]}>
8282

8383
```res example
84-
@bs.val @bs.scope(("window", "___location", "ancestorOrigins"))
84+
@val @scope(("window", "___location", "ancestorOrigins"))
8585
external length: int = "length"
8686
```
8787
```js

pages/docs/manual/latest/bind-to-js-function.mdx

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Binding a JS function is like binding any other value:
1212

1313
```res example
1414
// Import nodejs' path.dirname
15-
@bs.module("path") external dirname: string => string = "dirname"
15+
@module("path") external dirname: string => string = "dirname"
1616
let root = dirname("/User/github") // returns "User"
1717
```
1818
```js
@@ -43,7 +43,7 @@ It'd be nice if on ReScript's side, we can bind & call `draw` while labeling thi
4343
<CodeTab labels={["ReScript", "JS Output"]}>
4444

4545
```res example
46-
@bs.module("MyGame")
46+
@module("MyGame")
4747
external draw: (~x: int, ~y: int, ~border: bool=?, unit) => unit = "draw"
4848
4949
draw(~x=10, ~y=20, ~border=true, ())
@@ -67,7 +67,7 @@ Note that you can freely reorder the labels on the ReScript side; they'll always
6767
<CodeTab labels={["ReScript", "JS Output"]}>
6868

6969
```res example
70-
@bs.module("MyGame")
70+
@module("MyGame")
7171
external draw: (~x: int, ~y: int, ~border: bool=?, unit) => unit = "draw"
7272
7373
draw(~x=10, ~y=20, ())
@@ -84,14 +84,14 @@ MyGame.draw(10, 20, undefined);
8484

8585
## Object Method
8686

87-
Functions attached to a JS objects (other than JS modules) require a special way of binding to them, using `bs.send`:
87+
Functions attached to a JS objects (other than JS modules) require a special way of binding to them, using `send`:
8888

8989
<CodeTab labels={["ReScript", "JS Output"]}>
9090

9191
```res example
9292
type document // abstract type for a document object
93-
@bs.send external getElementById: (document, string) => Dom.element = "getElementById"
94-
@bs.val external doc: document = "document"
93+
@send external getElementById: (document, string) => Dom.element = "getElementById"
94+
@val external doc: document = "document"
9595
9696
let el = getElementById(doc, "myId")
9797
```
@@ -101,20 +101,20 @@ var el = document.getElementById("myId");
101101

102102
</CodeTab>
103103

104-
In a `bs.send`, the object is always the first argument. Actual arguments of the method follow (this is a bit what modern OOP objects are really).
104+
In a `send`, the object is always the first argument. Actual arguments of the method follow (this is a bit what modern OOP objects are really).
105105

106106
### Chaining
107107

108108
Ever used `foo().bar().baz()` chaining ("fluent api") in JS OOP? We can model that in ReScript too, through the [pipe operator](pipe.md).
109109

110110
## Variadic Function Arguments
111111

112-
You might have JS functions that take an arbitrary amount of arguments. ReScript supports modeling those, under the condition that the arbitrary arguments part is homogenous (aka of the same type). If so, add `bs.variadic` to your `external`.
112+
You might have JS functions that take an arbitrary amount of arguments. ReScript supports modeling those, under the condition that the arbitrary arguments part is homogenous (aka of the same type). If so, add `variadic` to your `external`.
113113

114114
<CodeTab labels={["ReScript", "JS Output"]}>
115115

116116
```res example
117-
@bs.module("path") @bs.variadic
117+
@module("path") @variadic
118118
external join: array<string> => string = "join"
119119
120120
let v = join(["a", "b"])
@@ -126,7 +126,7 @@ var v = Path.join("a", "b");
126126

127127
</CodeTab>
128128

129-
`bs.module` will be explained in [Import from/Export to JS](import-from-export-to-js.md).
129+
`module` will be explained in [Import from/Export to JS](import-from-export-to-js.md).
130130

131131
## Modeling Polymorphic Function
132132

@@ -139,9 +139,9 @@ If you can exhaustively enumerate the many forms an overloaded JS function can t
139139
<CodeTab labels={["ReScript", "JS Output"]}>
140140

141141
```res example
142-
@bs.module("MyGame") external drawCat: unit => unit = "draw"
143-
@bs.module("MyGame") external drawDog: (~giveName: string) => unit = "draw"
144-
@bs.module("MyGame") external draw: (string, ~useRandomAnimal: bool) => unit = "draw"
142+
@module("MyGame") external drawCat: unit => unit = "draw"
143+
@module("MyGame") external drawDog: (~giveName: string) => unit = "draw"
144+
@module("MyGame") external draw: (string, ~useRandomAnimal: bool) => unit = "draw"
145145
```
146146
```js
147147
// Empty output
@@ -151,7 +151,7 @@ If you can exhaustively enumerate the many forms an overloaded JS function can t
151151

152152
Note how all three externals bind to the same JS function, `draw`.
153153

154-
### Trick 2: Polymorphic Variant + `bs.unwrap`
154+
### Trick 2: Polymorphic Variant + `unwrap`
155155

156156
If you have the irresistible urge of saying "if only this JS function argument was a variant instead of informally being either `string` or `int`", then good news: we do provide such `external` features through annotating a parameter as a polymorphic variant! Assuming you have the following JS function you'd like to bind to:
157157

@@ -172,10 +172,10 @@ Here, `padding` is really conceptually a variant. Let's model it as such.
172172
<CodeTab labels={["ReScript", "JS Output"]}>
173173

174174
```res example
175-
@bs.val
175+
@val
176176
external padLeft: (
177177
string,
178-
@bs.unwrap [
178+
@unwrap [
179179
| #Str(string)
180180
| #Int(int)
181181
])
@@ -190,21 +190,21 @@ padLeft("Hello World", "Message from ReScript: ");
190190

191191
</CodeTab>
192192

193-
Obviously, the JS side couldn't have an argument that's a polymorphic variant! But here, we're just piggy backing on poly variants' type checking and syntax. The secret is the `@bs.unwrap` annotation on the type. It strips the variant constructors and compile to just the payload's value. See the output.
193+
Obviously, the JS side couldn't have an argument that's a polymorphic variant! But here, we're just piggy backing on poly variants' type checking and syntax. The secret is the `@unwrap` annotation on the type. It strips the variant constructors and compile to just the payload's value. See the output.
194194

195195
## Constrain Arguments Better
196196

197-
Consider the Node `fs.readFileSync`'s second argument. It can take a string, but really only a defined set: `"ascii"`, `"utf8"`, etc. You can still bind it as a string, but we can use poly variants + `bs.string` to ensure that our usage's more correct:
197+
Consider the Node `fs.readFileSync`'s second argument. It can take a string, but really only a defined set: `"ascii"`, `"utf8"`, etc. You can still bind it as a string, but we can use poly variants + `string` to ensure that our usage's more correct:
198198

199199
<CodeTab labels={["ReScript", "JS Output"]}>
200200

201201
```res example
202-
@bs.module("fs")
202+
@module("fs")
203203
external readFileSync: (
204204
~name: string,
205-
@bs.string [
205+
@string [
206206
| #utf8
207-
| @bs.as("ascii") #useAscii
207+
| @as("ascii") #useAscii
208208
],
209209
) => string = "readFileSync"
210210
@@ -217,21 +217,21 @@ Fs.readFileSync("xx.txt", "ascii");
217217

218218
</CodeTab>
219219

220-
- Attaching `@bs.string` to the whole poly variant type makes its constructor compile to a string of the same name.
221-
- Attaching a `@bs.as("bla")` to a constructor lets you customize the final string.
220+
- Attaching `@string` to the whole poly variant type makes its constructor compile to a string of the same name.
221+
- Attaching a `@as("bla")` to a constructor lets you customize the final string.
222222

223223
And now, passing something like `"myOwnUnicode"` or other variant constructor names to `readFileSync` would correctly error.
224224

225-
Aside from string, you can also compile an argument to an int, using `bs.int` instead of `bs.string` in a similar way:
225+
Aside from string, you can also compile an argument to an int, using `int` instead of `string` in a similar way:
226226

227227
<CodeTab labels={["ReScript", "JS Output"]}>
228228

229229
```res example
230-
@bs.val
230+
@val
231231
external testIntType: (
232-
@bs.int [
232+
@int [
233233
| #onClosed
234-
| @bs.as(20) #onOpen
234+
| @as(20) #onOpen
235235
| #inBinary
236236
])
237237
=> int = "testIntType"
@@ -254,10 +254,10 @@ One last trick with polymorphic variants:
254254
```res example
255255
type readline
256256
257-
@bs.send
257+
@send
258258
external on: (
259259
readline,
260-
@bs.string [
260+
@string [
261261
| #close(unit => unit)
262262
| #line(string => unit)
263263
]
@@ -290,9 +290,9 @@ Sometimes it's convenient to bind to a function using an `external`, while passi
290290
<CodeTab labels={["ReScript", "JS Output"]}>
291291

292292
```res example
293-
@bs.val
293+
@val
294294
external processOnExit: (
295-
@bs.as("exit") _,
295+
@as("exit") _,
296296
int => unit
297297
) => unit = "process.on"
298298
@@ -308,7 +308,7 @@ process.on("exit", function (exitCode) {
308308

309309
</CodeTab>
310310

311-
The `@bs.as("exit")` and the placeholder `_` argument together indicates that you want the first argument to compile to the string `"exit"`. You can also use any JSON literal with `bs.as`: `` @bs.as(json`true`) ``, `` @bs.as(json`{"name": "John"}`) ``, etc.
311+
The `@as("exit")` and the placeholder `_` argument together indicates that you want the first argument to compile to the string `"exit"`. You can also use any JSON literal with `as`: `` @as(json`true`) ``, `` @as(json`{"name": "John"}`) ``, etc.
312312

313313
## Curry & Uncurry
314314

@@ -338,7 +338,7 @@ Unfortunately, due to JS not having currying because of the aforementioned reaso
338338

339339
ReScript tries to do #1 as much as it can. Even when it bails and uses #2's currying mechanism, it's usually harmless.
340340

341-
**However**, if you encounter #3, heuristics are not good enough: you need a guaranteed way of fully applying a function, without intermediate currying steps. We provide such guarantee through the use of the `@bs` "uncurrying" annotation on a function declaration & call site.
341+
**However**, if you encounter #3, heuristics are not good enough: you need a guaranteed way of fully applying a function, without intermediate currying steps. We provide such guarantee through the use of the ["uncurrying" syntax](./function#uncurried-function) on a function declaration & call site.
342342

343343
### Solution: Use Guaranteed Uncurrying
344344

@@ -348,7 +348,7 @@ ReScript tries to do #1 as much as it can. Even when it bails and uses #2's curr
348348

349349
```res example
350350
type timerId
351-
@bs.val external setTimeout: ((. unit) => unit, int) => timerId = "setTimeout"
351+
@val external setTimeout: ((. unit) => unit, int) => timerId = "setTimeout"
352352
353353
let id = setTimeout((.) => Js.log("hello"), 1000)
354354
```
@@ -370,12 +370,12 @@ The above solution is safe, guaranteed, and performant, but sometimes visually a
370370

371371
<!-- TODO: is this up-to-date info? -->
372372

373-
Then try `@bs.uncurry`:
373+
Then try `@uncurry`:
374374

375375
<CodeTab labels={["ReScript", "JS Output"]}>
376376

377377
```res example
378-
@bs.send external map: (array<'a>, @bs.uncurry ('a => 'b)) => array<'b> = "map"
378+
@send external map: (array<'a>, @uncurry ('a => 'b)) => array<'b> = "map"
379379
map([1, 2, 3], x => x + 1)
380380
```
381381
```js
@@ -384,7 +384,7 @@ map([1, 2, 3], x => x + 1)
384384

385385
</CodeTab>
386386

387-
In general, `bs.uncurry` is recommended; the compiler will do lots of optimizations to resolve the currying to uncurrying at compile time. However, there are some cases the compiler can't optimize it. In these cases, it will be converted to a runtime check.
387+
In general, `uncurry` is recommended; the compiler will do lots of optimizations to resolve the currying to uncurrying at compile time. However, there are some cases the compiler can't optimize it. In these cases, it will be converted to a runtime check.
388388

389389
## Modeling `this`-based Callbacks
390390

@@ -396,16 +396,16 @@ x.onload = function(v) {
396396
}
397397
```
398398

399-
Here, `this` would point to `x` (actually, it depends on how `onload` is called, but we digress). It's not correct to declare `x.onload` of type `(. unit) -> unit`. Instead, we introduced a special attribute, `bs.this`, which allows us to type `x` as so:
399+
Here, `this` would point to `x` (actually, it depends on how `onload` is called, but we digress). It's not correct to declare `x.onload` of type `(. unit) -> unit`. Instead, we introduced a special attribute, `this`, which allows us to type `x` as so:
400400

401401
<CodeTab labels={["ReScript", "JS Output"]}>
402402

403403
```res example
404404
type x
405-
@bs.val external x: x = "x"
406-
@bs.set external setOnload: (x, @bs.this ((x, int) => unit)) => unit = "onload"
407-
@bs.get external resp: x => int = "response"
408-
setOnload(x, @bs.this ((o, v) => Js.log(resp(o) + v)))
405+
@val external x: x = "x"
406+
@set external setOnload: (x, @this ((x, int) => unit)) => unit = "onload"
407+
@get external resp: x => int = "response"
408+
setOnload(x, @this ((o, v) => Js.log(resp(o) + v)))
409409
```
410410
```js
411411
x.onload = function (v) {
@@ -416,19 +416,19 @@ x.onload = function (v) {
416416

417417
</CodeTab>
418418

419-
`bs.this` has its first parameter is reserved for `this` and for arity of 0, there is no need for a redundant `unit` type.
419+
`this` has its first parameter is reserved for `this` and for arity of 0, there is no need for a redundant `unit` type.
420420

421421
## Function Nullable Return Value Wrapping
422422

423-
For JS functions that return a value that can also be `undefined` or `null`, we provide `@bs.return(...)`. To automatically convert that value to an `option` type (recall that ReScript `option` type's `None` value only compiles to `undefined` and not `null`).
423+
For JS functions that return a value that can also be `undefined` or `null`, we provide `@return(...)`. To automatically convert that value to an `option` type (recall that ReScript `option` type's `None` value only compiles to `undefined` and not `null`).
424424

425425
<CodeTab labels={["ReScript", "JS Output"]}>
426426

427427
```res example
428428
type element
429429
type dom
430430
431-
@bs.send @bs.return(nullable)
431+
@send @return(nullable)
432432
external getElementById: (dom, string) => option<element> = "getElementById"
433433
434434
let test = dom => {
@@ -454,7 +454,7 @@ function test(dom) {
454454

455455
</CodeTab>
456456

457-
`bs.return(nullable)` attribute will automatically convert `null` and `undefined` to `option` type.
457+
`return(nullable)` attribute will automatically convert `null` and `undefined` to `option` type.
458458

459459
Currently 4 directives are supported: `null_to_opt`, `undefined_to_opt`, `nullable` and `identity`.
460460

0 commit comments

Comments
 (0)