New check: useless branches in update
Closed this issue · 0 comments
brianvanburken commented
We start developing our Elm files with a Msg
containing a branch called NoOp
which just returns the model unchanged and most of the time accompanied with Cmd.none
. As the development progresses these branches become useless. Below is an SSCE showing an example where NoOp
does not have any uses. Removing these kind of branches should clean up code a bit.
module Main exposing (..)
import Html exposing (Html)
import Html.Events as Event
type alias Model =
Int
model : Model
model =
0
type Msg
= NoOp
| Inc
| Dec
update : Msg -> Model -> Model
update msg model =
case msg of
Inc ->
model + 1
Dec ->
model - 1
NoOp ->
model
view : Model -> Html Msg
view model =
Html.div []
[ Html.button [ Event.onClick Dec ] [ Html.text "-" ]
, Html.div [] [ Html.text (toString model) ]
, Html.button [ Event.onClick Inc ] [ Html.text "+" ]
]
main : Program Never Model Msg
main =
Html.beginnerProgram
{ view = view
, model = model
, update = update
}