File tree Expand file tree Collapse file tree 2 files changed +50
-2
lines changed Expand file tree Collapse file tree 2 files changed +50
-2
lines changed Original file line number Diff line number Diff line change @@ -6,22 +6,29 @@ summary: "This is the `@send` decorator."
66category : " 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
1618type document
1719@send external getElementById: (document, string) => Dom.element = "getElementById"
1820@val external doc: document = "document"
19-
2021let 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
2429var el = document .getElementById (" myId" );
30+
31+ var a = [1 , 2 , 3 ].fill (99 );
2532```
2633
2734</CodeTab >
Original file line number Diff line number Diff line change 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 )
You can’t perform that action at this time.
0 commit comments