From 8ffb34682aaa606cddf8435c043ddbed3436bb8b Mon Sep 17 00:00:00 2001 From: nojaf Date: Thu, 23 May 2024 14:22:41 +0200 Subject: [PATCH] Add nested function call example --- .../manual/latest/bind-to-js-function.mdx | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/pages/docs/manual/latest/bind-to-js-function.mdx b/pages/docs/manual/latest/bind-to-js-function.mdx index ba9b554a9..794784074 100644 --- a/pages/docs/manual/latest/bind-to-js-function.mdx +++ b/pages/docs/manual/latest/bind-to-js-function.mdx @@ -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. + + +```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 = "create" +``` +```js +import Stripe from "stripe"; + +var stripe = new Stripe("sk_..."); +var session = stripe.checkout.sessions.create({}); +``` + + ## 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`.