Skip to content

Add nested function call example #864

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 1 commit into from
May 24, 2024
Merged
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
28 changes: 28 additions & 0 deletions pages/docs/manual/latest/bind-to-js-function.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,34 @@ In a `send`, the object is always the first argument. Actual arguments of the me

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

### Nested function call

`@send` can also accept a `@scope(("itemOne","itemTwo"))` to access a function on a nested property.

<CodeTab labels={["ReScript", "JS Output"]}>
```res example
type stripe

@module("stripe") @new
external make: string => stripe = "default"

type createSession = {}

type sessionResult

@send
@scope(("checkout", "sessions"))
external createCheckoutSession: (stripe, createSession) =>
Promise.t<sessionResult> = "create"
```
```js
import Stripe from "stripe";

var stripe = new Stripe("sk_...");
var session = stripe.checkout.sessions.create({});
```
</CodeTab>

## Variadic Function Arguments

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`.
Expand Down