This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
We were not able to find the expected elm-package.json file at this tag.
Tag 1.1.2
Committed At 2020-09-07 22:56:07 UTC

Modules

    README

    KeyedList

    A KeyedList is a list that assigns each item a locally unique identifier, which makes it easier to later update or remove items via a Msg. It encapsulates the ids, so your Model doesn't need to keep track of them.

    Instead of

    type alias Model =
        { submodels : List (Int, SubModel)
          uid : Int
          ...
        }
    
    
    update : Msg -> Model -> Model
    update msg model =
        case msg of
        Add submodel ->
            { model
                | submodels = (model.uid, submodel) :: model.submodels
            , uid = model.uid + 1
            }
        
        Update id submsg ->
            let
            updateHelper (subId, submodel) =
                if subId == id then
                (subId, SubModel.update submsg submodel)
                else
                (subId, submodel)
            in
            { model | submodels = List.map updateHelper model.submodels }
    
        Remove id ->
            let
            removeHelper (subId, _) = subId /= id
            in
            { model | submodels = List.filter removeHelper model.submodels }
    

    you can write

    type alias Model =
        { submodels : KeyedList SubModel
          ...
        }
    
    
    update : Msg -> Model -> Model
    update msg model =
        case msg of
        Add submodel ->
            { model | submodels = KeyedList.cons submodel model.submodels ]
    
        Update key submsg ->
            { model | submodels = KeyedList.update key (SubModel.update submsg) model.submodels }
    
        Remove key ->
            { model | submodels = KeyedList.remove key model.submodels }