On Thursday, January 19, 2017 at 5:18:33 AM UTC, Max Goldstein wrote: > > For Elm, I output one (big) file called Model.elm, that gives me the data >> model mapped onto Elm, and encoders and decoders for it. Then for each >> grouping of endpoints (each service implemented in Java provides the >> grouping) I generate one Elm file that implements the Http logic for the >> service. >> > > I've come to the same file structure, because JSON API allows for included > resources. For example, articles can include their author an vice versa, > which means those decoders have to be defined in a common file. I'm trying > to wrap them in one module per resource, though. >
In the general case one entity can reference another, and that other can reference the original (directly or via a chain of other references). In other words mutual recursion is possible. For that reason, I ended up wrapping all my records as single constructor union types. A linked entity may be fetched or not. So I ended up using Maybes, except in situations where I know it will always be eagerly fetched. These added complexity to the encoders/decoders but at least I got things into a form that would handle the most general cases that I needed to work with. Another possibility is that for linked entities is that there are really 4 states; Nothing, meaning that the server has explicitly told me nothing is linked; Just a, meaning there is some linked entity and it has been fetched; Unknown, meaning that the server did not provide an explicit value so I don't know if something is linked or not; Ref id, meaning the server gave me the id of a linked entity, but did not fetch the actual entity. I couldn't face handling all of this, but might come back to it later. I use Nothing to mean really nothing or unknown and Just a to hold a linked entity or a linked entity in a degenerate form where just the id is present. It would be nice if there was a simple mechanism to expand a Ref id into a Just entity, by which I mean a function I could call and pass in the reference and it will fetch it and then place the results back into a new data structure in the correct place. Then I could represent the data models as HAL or JSON-LD and then codegen a client in Elm for it that gives me a convenient tool to navigate around and fetch data. -- You received this message because you are subscribed to the Google Groups "Elm Discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.