I'm looking at some documentation for JS and it's using a string as a makeshift 'enum'. It'd be better to represent this as an algebraic data type, ADT, in my application; however, I'm not really sure what is the best way to turn that ADT into a String
on an object for the foreign function interface, FFI, to consume. Given conceptually:
data Foo = Bar | Baz
type Qux = { foo :: Foo }
foreign import quux :: forall e. Qux -> Eff (console :: CONSOLE | e) Unit
main = do
quux { foo : Bar }
and where qux
is { foo : "bar" | "baz" }
exports.quux = function(qux) {
return function() {
console.log(qux)
//=> Object { foo : "bar" }
}
}
In Elm I'd use Json.Encode
in core
to transform the record into a JS object to pass it along, but I'm not sure of the analog in PureScript.