Record vs. Js.t Object


#1

I’m trying to figure out what the pros and cons are for converting JS object <-> record (using [@bs.deriving jsConverter]) or just using the Js.t type in all of my Reason code. I’m looking to slowly implement parts of our codebase with Reason, and it seems that a record has cleaner syntax and more fully “embraces” ReasonML (immutable, better support for typing etc.).

Obviously there is some overhead for converting types, but it somehow seems more pure to do it this way. Any thoughts?


#2

Good question, I tend to use records internally for example inside React component state because they’re easy to update immutably, and Js.t objects for cross-module communication because they’re close to JSON format and if they get printed out or encoded somewhere, they look like what people would expect to see as output.


#3

Yeah, that makes sense. I was thinking records internally, Js.t when crossing boundary between Reason and JS code.