6 ms·
And records. You would typically define a record type to do the heavy lifting in, and do some lightweight conversions to and from JS. Here's an example: [@
by yawaramin 9y ago
And records. You would typically define a record type to do the heavy lifting in, and do some lightweight conversions to and from JS. Here's an example:
[@bs.deriving jsConverter]
type person = {name: string, age: int};
let bob = {name: "Bob", age: 33};
let olderBob = {...bob, age: bob.age + 1};
let () = Js.log(personToJs(olderBob));
- k__ 9y agoBut the records wouldn't use variants.
- yawaramin 9y agoNope, you can definitely use variants in the records. BuckleScript (the compiler) will automatically convert them into JavaScript-friendly representations. Or you can also pick custom representations for each variant case.
- k__ 9y agoAh, yes if you only go from Reason to JS, becaue Reason is much richer. I was thinking about going from a JS library to Reason, where you basically get bags full of strings.