From bc816c32af1ed9908558435708a93c6f3b536495 Mon Sep 17 00:00:00 2001 From: Kevan Stannard Date: Sun, 9 May 2021 07:44:20 +1000 Subject: [PATCH 1/3] Syntax lookup: Send pipe decorator --- misc_docs/syntax/decorator_send.mdx | 11 +++++-- misc_docs/syntax/decorator_send_pipe.mdx | 41 ++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 misc_docs/syntax/decorator_send_pipe.mdx diff --git a/misc_docs/syntax/decorator_send.mdx b/misc_docs/syntax/decorator_send.mdx index ed2a5bde1..50229f0cc 100644 --- a/misc_docs/syntax/decorator_send.mdx +++ b/misc_docs/syntax/decorator_send.mdx @@ -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 ```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); ``` diff --git a/misc_docs/syntax/decorator_send_pipe.mdx b/misc_docs/syntax/decorator_send_pipe.mdx new file mode 100644 index 000000000..7fd977ac5 --- /dev/null +++ b/misc_docs/syntax/decorator_send_pipe.mdx @@ -0,0 +1,41 @@ +--- +id: "send-pipe-decorator" +keywords: ["send", "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 + + + +```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 = fillInPlace2([1, 2, 3], 99) +``` + +```js +var el = document.getElementById("myId"); + +var a = [1, 2, 3].fill(99); +``` + + + +### References + +* [Bind to JS Function](/docs/manual/latest/bind-to-js-function) \ No newline at end of file From 350ad016161a2bd56379bdd64f0498756407292d Mon Sep 17 00:00:00 2001 From: Kevan Stannard Date: Sun, 9 May 2021 09:07:15 +1000 Subject: [PATCH 2/3] Fix incorrect syntax --- misc_docs/syntax/decorator_send_pipe.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc_docs/syntax/decorator_send_pipe.mdx b/misc_docs/syntax/decorator_send_pipe.mdx index 7fd977ac5..c36085b4a 100644 --- a/misc_docs/syntax/decorator_send_pipe.mdx +++ b/misc_docs/syntax/decorator_send_pipe.mdx @@ -25,7 +25,7 @@ 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 = fillInPlace2([1, 2, 3], 99) +let a = fillInPlace(99, [1, 2, 3]) ``` ```js From 416438077f9c0c09cc2142416f9ac474cf50765b Mon Sep 17 00:00:00 2001 From: Kevan Stannard Date: Sun, 9 May 2021 09:10:11 +1000 Subject: [PATCH 3/3] Add "pipe" keyword --- misc_docs/syntax/decorator_send_pipe.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc_docs/syntax/decorator_send_pipe.mdx b/misc_docs/syntax/decorator_send_pipe.mdx index c36085b4a..ac3aa628e 100644 --- a/misc_docs/syntax/decorator_send_pipe.mdx +++ b/misc_docs/syntax/decorator_send_pipe.mdx @@ -1,6 +1,6 @@ --- id: "send-pipe-decorator" -keywords: ["send", "decorator"] +keywords: ["send", "pipe", "decorator"] name: "@bs.send.pipe" summary: "This is the `@bs.send.pipe` decorator." category: "decorators"