Skip to content

Commit 39d5969

Browse files
authored
Merge pull request #348 from kevanstannard/syntax-lookup-send-pipe
Syntax lookup: Send pipe decorator
2 parents 059022e + 4164380 commit 39d5969

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

misc_docs/syntax/decorator_send.mdx

+9-2
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,29 @@ summary: "This is the `@send` decorator."
66
category: "decorators"
77
---
88

9-
The `@send` decorator is used to bind to a method on an object.
9+
The `@send` decorator is used to bind to a method on an object or array.
1010

1111
### Example
1212

1313
<CodeTab labels={["ReScript", "JS Output"]}>
1414

1515
```res
16+
17+
// Bind to a method on an object
1618
type document
1719
@send external getElementById: (document, string) => Dom.element = "getElementById"
1820
@val external doc: document = "document"
19-
2021
let el = getElementById(doc, "myId")
22+
23+
// Bind to a method on an array
24+
@send external fillInPlace: (array<'a>, 'a) => array<'a> = "fill"
25+
let a = fillInPlace([1, 2, 3], 99)
2126
```
2227

2328
```js
2429
var el = document.getElementById("myId");
30+
31+
var a = [1, 2, 3].fill(99);
2532
```
2633

2734
</CodeTab>
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
id: "send-pipe-decorator"
3+
keywords: ["send", "pipe", "decorator"]
4+
name: "@bs.send.pipe"
5+
summary: "This is the `@bs.send.pipe` decorator."
6+
category: "decorators"
7+
---
8+
9+
The `@bs.send.pipe` decorator is used to bind to a method on an object or array.
10+
11+
> This decorator has been deprecated. Use the [@send](https://rescript-lang.org/docs/manual/latest/bind-to-js-function) decorator instead.
12+
13+
### Example
14+
15+
<CodeTab labels={["ReScript", "JS Output"]}>
16+
17+
```res
18+
// Bind to a method on an object
19+
type document
20+
@bs.send.pipe(: document)
21+
external getElementById: string => Dom.element = "getElementById"
22+
@val external doc: document = "document"
23+
let el = getElementById("myId", doc)
24+
25+
// Bind to a method on an array
26+
@bs.send.pipe(: array<'a>)
27+
external fillInPlace: 'a => array<'a> = "fill"
28+
let a = fillInPlace(99, [1, 2, 3])
29+
```
30+
31+
```js
32+
var el = document.getElementById("myId");
33+
34+
var a = [1, 2, 3].fill(99);
35+
```
36+
37+
</CodeTab>
38+
39+
### References
40+
41+
* [Bind to JS Function](/docs/manual/latest/bind-to-js-function)

0 commit comments

Comments
 (0)