Hi all,
First of all, thanks for providing this forum! I’m an avid JavaScript developer, but just getting into ReScript.
The documentation and forum so far have been super helpful.
I’m gradually migrating a CucumberJS project to ReScript. But running into issues because of how CucumberJS passes ‘this’.
The relevant snippet of JavaScript I’m trying to convert:
var Cucumber = require("@cucumber/cucumber");
Cucumber.Given("{string} is authenticated", function (username) {
return authenticateUser(this, username);
});
My (wip) conversion to ReScript:
@module("@cucumber/cucumber")
external given: (string, 'b) => unit = "Given"
@module("../authenticate")
external authenticateUser: ('a, string) => Js.Promise.t<unit> = "authenticateUser"
given("{string} is authenticated", (~userName: string) : Js.Promise.t<unit> => {
authenticate(@this, userName)
})
What I don’t understand is how I should deal with ‘this’ in ReScript. What I want to achieve is the example code in JS above. Where ‘this’ is being passed to the authenticateUser
function.
I’ve read Bind to JS Function | ReScript Language Manual but I’m struggling to understand how to apply that to my code. Especially since I don’t know what will be the caller of this function.
Many thanks in advance, keep up the good work!