My initial reaction is also #3. I think it's totally sensible to do a bit of transformation when serializing/deserializing, and more important to optimize your model for its use in view and update.
On Friday, 12 August 2016 23:03:34 UTC+10, Robert Walter wrote: > > Hello, > > following scenario: In my Model, I want to keep track of a collection of > items as well as the currently active item. Sounds simple enough, but there > are some constraints. I want to serialize my Model (use programWithFlags), > so I cannot use a Dict directly to the best of my knowledge. I need to be > able to sort the collection and be able to append items at the beginning as > well at the end. > I've come up with the following options and it would be appreciated if I > could get some feedback on what the community thinks is best and why. > > Option 1: List and explicit Item > type alias Model = > { collection : List Item > , itemActive : Item > } > > > type alias Item = > { name : String > } > > Downside: I have to manually update the list if the item changes (it's > what I have in place currently and it is somewhat obvious to me that this > is not best). > > Option 2: List with index > type alias Model = > { collection : List Item > , itemActive : Int > } > > > type alias Item = > { name : String > } > > Downside: accessing a random item in a list is expensive (although in > practice my collection is never going to be very long, it could get > arbitrarily long). > > Option 3: Dict with index > type alias Model = > { collection : Dict Int Item > , itemActive : Int > } > > > type alias Item = > { name : String > } > > Downside: Dict is not supported by programWithFlags, so I'd have to > transform it to a different representation for serialization > > Option 4: array with index > type alias Model = > { collection : Array Item > , itemActive : Item > } > > > type alias Item = > { name : String > } > > Downside: I need to perform some operations that don't seem to be first > class array operations, namely sort the array by Item.name and insert items > at the front > > I think I know how to implement each of these approaches, but maybe I'm > missing an even better fit for my use case. Currently I prefer Option 3. > Even though it might need a bit more work on the serialization / > de-serialization side, I feel like a Dict would be the best fit for my use > case. > > Thanks in advance, > Robert > -- 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.