forcecraft/aion

refactor(elm): DRY out the main update code

Opened this issue · 0 comments

Type

Refactor

Current behaviour
Our code gets quite repetitive

      MkUserMsg subMsg ->
            if User.Api.unauthorized subMsg then
                update (MkUserMsg Logout) model
            else
                let
                    ( updatedModel, cmd ) =
                        User.Update.update subMsg model.userData
                in
                    { model | userData = updatedModel } ! [ Cmd.map MkUserMsg cmd ]

      MkRankingMsg subMsg ->
            if Ranking.Api.unauthorized subMsg then
                update (MkUserMsg Logout) model
            else
                let
                    ( updatedModel, cmd ) =
                        Ranking.Update.update subMsg model.rankingData
                in
                    { model | rankingData = updatedModel } ! [ Cmd.map MkRankingMsg cmd ]

Expected behaviour
I think we could and we should make this flow more generic.

Motivation / use case
refactor