Consider changing runtime value representation of variants, because for now there is a pain in the ass to serialize and deserialize them manually.
Variants are super-duper cool for making strongly typed event buses, but it doesn't work out of the box :(
Workaround:
let serializeVariant: 'a => string = [%bs.raw
{|
function (variant) {
return JSON.stringify({ tag: variant.tag, variant };
}
|}
];
let deserializeVariant: string => 'a = [%bs.raw
{|
function (serializedString) {
const { tag, variant } = JSON.parse(serializedString);
variant.tag = tag;
return variant;
}
|}
];
Consider changing runtime value representation of variants, because for now there is a pain in the ass to serialize and deserialize them manually. Variants are super-duper cool for making strongly typed event buses, but it doesn't work out of the box :(
Workaround: