So, haxe objects containing enums have to be “serialized” to simple javascript objects containing only object literals (no functions etc…) Elnabo’s json2object json2object (3.9.0) (based on Nadako’s GitHub - nadako/hxjsonast: Parse JSON into position-aware AST with Haxe!) is my goto solution for serializing haxe objects to plain json and back, but this solution (of course) results in a json string, not an object.
Someone know of a lightweight and quick object translator around that can convert a haxe object to/from a simple js object that can be handled by the structured clone algorithm?
Sorry if I misunderstood your question, Kevin! I could postMessage the Haxe objects as strings, you mean…? Yes, that should work, of course. Just thought that I would shave of some ms’s by not having to convert them to/from strings… I guess that I have some profiling work to do…
The current representation of enums is chosen to actually work with JSON (it is a plain object that refers to its own enum indirectly via name) and as a result it also fits with the structured clone algorithm. The two remaining problems then are:
Maps. For this I would advise making your own implementation of Map on top of js.lib.Map. You can call Context.defineType in a --macro to take precedence over the stdlib version.
Your own classes. There’s not much you can do about this.
If you want to squeeze out maximum performance, then I would suggest not using your own classes, as that will avoid any translation at all (you can use macros to statically ensure the data sent is clonable). If you do, it really doesn’t matter whether you build a string or another object graph.