Compiling Gleam to serializable js #2875
nadavhames
started this conversation in
Ideas & suggestions
Replies: 2 comments 2 replies
-
|
Beta Was this translation helpful? Give feedback.
0 replies
-
in javascript classes are a thin abstraction on the underlying object prototype system... you should be able to just use built-in features when trying to bridge your existing JS project with your gleam compiled output, unless i'm misunderstanding what you're trying to accomplish link: |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Lets say I have a record in Gleam like this:
...and I compile it to js. The output I get uses classes:
This is fine, but what if my js codebase requires serializability of data/data structures? Classes in js afaik are not serializable. One idea to make a serializable structure would be to have a serializable flag in the js target config which tells the compiler to emit pure js objects instead of classes. It could look something roughly like this:
For each of the Teacher, Human, and Me types, helper functions could also be emitted for easy object creation and also for identity checking.
Alternatively, it might be nice to have a helper that comes with the emitted js using the class based setup that can serialize and deserialize the class structure into objects.
Would be interested to hear what insights people have on this topic!
Beta Was this translation helpful? Give feedback.
All reactions