update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
-- ...
RemoveTrack id -> (1)
( { model \| tracks = List.filter (\( rowId, _ ) -> rowId /= id) model.tracks
}
, Cmd.none
)
MoveTrackUp id ->
-- ...
MoveTrackDown id ->
-- ...
ModifyTrack id trackRowMsg ->
case (modifyTrack id trackRowMsg model) of (2)
Just ( updModel, Nothing ) -> (3)
( model, Cmd.none )
Just ( updModel, Just dispatchMsg ) -> (4)
handleDispatch id dispatchMsg updModel
_ ->
( model, Cmd.none ) (5)
modifyTrack : TrackRowId -> TrackRow.Msg -> Model -> Maybe ( Model, Maybe TrackRow.DispatchMsg )
modifyTrack id msg model = (6)
ListX.find (\( trackId, _ ) -> id == trackId) model.tracks
\|> Maybe.map (\( _, trackModel ) -> TrackRow.update msg trackModel)
\|> Maybe.map
(\( updTrack, dispatchMsg ) ->
( maybeAddPristine
{ model
\| tracks =
ListX.replaceIf (\( i, _ ) -> i == id)
( id, updTrack )
model.tracks
}
, dispatchMsg
)
)
handleDispatch : TrackRowId -> TrackRow.DispatchMsg -> Model -> ( Model, Cmd Msg )
handleDispatch id msg model = (7)
case msg of
TrackRow.MoveDown ->
update (MoveTrackDown id) model
TrackRow.MoveUp ->
update (MoveTrackUp id) model
TrackRow.Remove ->
update (RemoveTrack id) model