I would propose an Option 5: "array with index and separate key for sorting"
type alias Model = 
  { collection : Array Item
  , itemActive : Int
  }


type alias Item =
  { name : String 

  }


With option 1 you keep the active item in 2 places, which is not "One 
source of truth", so requires syncing data and stuff.

Conceptually, you really need two things to make this work:

   1. Some key to identify the item, to store in model.itemActive
   2. *Another* key for sorting the collection.

In Option 3, you would still need some other key inside the Dict value to 
use in sorting.
Otherwise you run into the same problems as in the other options with an 
Int key: after resort, model.itemActive no longer refers to the right item.

PS: Option 4 is titled "array with index" but it the code in fact "array 
with explicit item".
(You probably meant the code to be with index. Array with explicit item 
would not make much sense, because you lose the fast index-based get and 
set on arrays)

-- 
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.

Reply via email to