How to think about writing de/serializers in Fable? #2909
-
I've written a little thing to help us with our environment configuration of our fsharp applications. It only works in .NET at the moment, but I want to use this in our browser applications with Fable too. It's reflection-heavy so it doesn't work with Fable. I'm guessing I need to take quite a different approach but I'm not sure where to start. Can anyone point me toward techniques I could be using to implement Fable-compatible
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
There's some reflection support in Fable, but objects don't carry extra type info with them so it must be resolved at compile time (this is by design so Fable apps are compatible with JS tree shaking). The usual pattern is to offer two functions: one generic and inlined that gets the type info argument and just calls another function (not inlined) that receives the |
Beta Was this translation helpful? Give feedback.
There's some reflection support in Fable, but objects don't carry extra type info with them so it must be resolved at compile time (this is by design so Fable apps are compatible with JS tree shaking). The usual pattern is to offer two functions: one generic and inlined that gets the type info argument and just calls another function (not inlined) that receives the
Type
argument. You can see this pattern in Thoth.Json for example: https://github.com/thoth-org/Thoth.Json/blob/358ba12ac50ebac175bbfea98f9df20c0ddd1189/src/Decode.fs#L1233-L1238