#Record to JS object

1 messages · Page 1 of 1 (latest)

cedar trout
#

say I have a record like Person(name:, adress:, etc:) and I need to pass a js object containing the same information (maybe with some key names changes) to a third party js function.

What's the best way to convert the record to object?

#

my guess is: From the ffi.js import the record from the compiled mjs and do the conversion in js. Is that correct? Or maybe you don't even need to import, you can access the field directly.

#

it's not very type safe, maybe you can convert it to json from gleam first, and then from json to object. But it's not pretty

craggy stream
#

you want to pass the Person to some javascript (not the other way round) right?

cedar trout
#

yes

#

the other way around I dealt with decode/zero

craggy stream
#

then you can just pass it to the javascript without changing anything if the fields align

#

if the fields dont align then yeah solve this in javascript because its happening outside your gleam program