To make sure I understand the problem, the reason you need to modify the JS is that curried form does not maintain scope? It passes the showCardForm function reference to the curry function and then later calls it (which gives it no scope).
The problem is that depending on how you use a regular function it might be curried, or it might not, depending on what the compiler is able to infer about the function call.
To guarantee the JS is produced as a direct call maintaining scope, the binding must use uncurried form: type fattJs = {showCardForm: (. unit) => Js.Promise.t<handler>}
To call this from ReScript code add a . to the call, e.g. fattjs.showCardForm(.)
Alternatively you could make fattJs an opaque type and use a new external to call showCardForm, then regular function calls will always be uncurried.
OMG this is amazing! You were spot on @spyder. I knew it was a this scope issue, but had no idea how to fix it as all the uncurried stuff is over my head.
Is there any more resources to better learn and understand this uncurried concept? Something that will by the end force me to understand (.) and (. unit) means?
The link @woeps posted is a good place to start as it’s relevant to your use case, and also the uncurried function docs. You don’t really need to understand what it’s doing, though, just know that in cases where you require the JS to not be curried add a . to the function definition; it works for regular functions as well as externals.
let myUncurriedFunction = (. num) => num + 3
Js.log(myUncurriedFunction(. 3))
In this specific scenario however you might find the external style easier to follow than hand-crafting the correct record syntax style. Here is how to adjust your code for that:
And then instead of fattJs.showCardForm(.) call it with fattJs->showCardForm (this scenario is one of the reasons -> was created, so that it looks about the same if you squint).
The external is more idiomatic ReScript style, too, where functions are static rather than instanced fields (but it compiles to an instanced field reference thanks to @bs.send).