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..ac3aa628e --- /dev/null +++ b/misc_docs/syntax/decorator_send_pipe.mdx @@ -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 + + + +```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); +``` + + + +### References + +* [Bind to JS Function](/docs/manual/latest/bind-to-js-function) \ No newline at end of file