Skip to content

Commit c37b1b5

Browse files
authored
Add nested function call example (#864)
1 parent be78d05 commit c37b1b5

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

pages/docs/manual/latest/bind-to-js-function.mdx

+28
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,34 @@ In a `send`, the object is always the first argument. Actual arguments of the me
105105

106106
Ever used `foo().bar().baz()` chaining ("fluent api") in JS OOP? We can model that in ReScript too, through the [pipe operator](pipe.md).
107107

108+
### Nested function call
109+
110+
`@send` can also accept a `@scope(("itemOne","itemTwo"))` to access a function on a nested property.
111+
112+
<CodeTab labels={["ReScript", "JS Output"]}>
113+
```res example
114+
type stripe
115+
116+
@module("stripe") @new
117+
external make: string => stripe = "default"
118+
119+
type createSession = {}
120+
121+
type sessionResult
122+
123+
@send
124+
@scope(("checkout", "sessions"))
125+
external createCheckoutSession: (stripe, createSession) =>
126+
Promise.t<sessionResult> = "create"
127+
```
128+
```js
129+
import Stripe from "stripe";
130+
131+
var stripe = new Stripe("sk_...");
132+
var session = stripe.checkout.sessions.create({});
133+
```
134+
</CodeTab>
135+
108136
## Variadic Function Arguments
109137

110138
You might have JS functions that take an arbitrary amount of arguments. ReScript supports modeling those, under the condition that the arbitrary arguments part is homogenous (aka of the same type). If so, add `variadic` to your `external`.

0 commit comments

Comments
 (0)