Skip to content

Syntax lookup: Send pipe decorator #348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions misc_docs/syntax/decorator_send.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,29 @@ summary: "This is the `@send` decorator."
category: "decorators"
---

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

### Example

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

```res

// Bind to a method on an object
type document
@send external getElementById: (document, string) => Dom.element = "getElementById"
@val external doc: document = "document"

let el = getElementById(doc, "myId")

// Bind to a method on an array
@send external fillInPlace: (array<'a>, 'a) => array<'a> = "fill"
let a = fillInPlace([1, 2, 3], 99)
```

```js
var el = document.getElementById("myId");

var a = [1, 2, 3].fill(99);
```

</CodeTab>
Expand Down
41 changes: 41 additions & 0 deletions misc_docs/syntax/decorator_send_pipe.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
id: "send-pipe-decorator"
keywords: ["send", "pipe", "decorator"]
name: "@bs.send.pipe"
summary: "This is the `@bs.send.pipe` decorator."
category: "decorators"
---

The `@bs.send.pipe` decorator is used to bind to a method on an object or array.

> This decorator has been deprecated. Use the [@send](https://rescript-lang.org/docs/manual/latest/bind-to-js-function) decorator instead.

### Example

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

```res
// Bind to a method on an object
type document
@bs.send.pipe(: document)
external getElementById: string => Dom.element = "getElementById"
@val external doc: document = "document"
let el = getElementById("myId", doc)

// Bind to a method on an array
@bs.send.pipe(: array<'a>)
external fillInPlace: 'a => array<'a> = "fill"
let a = fillInPlace(99, [1, 2, 3])
```

```js
var el = document.getElementById("myId");

var a = [1, 2, 3].fill(99);
```

</CodeTab>

### References

* [Bind to JS Function](/docs/manual/latest/bind-to-js-function)