DEV Community

Discussion on: Right clicks & Elm

Collapse
 
zwilias profile image
Ilias Van Peer

One possibility to keep ignored events out of your update and - incidentally - encourage some more reuse, is to move the decision into the decoder:

mouseLeftClick : Json.Decoder Position
mouseLeftClick =
    Json.field "button" Json.int
        |> Json.andThen (\button ->
            if button == 2 then
                fail "I'm ignored!"
            else
                Mouse.position
        )

The gist is that if an event-decoder fails, the event just happens but no message is sent to Elm.

Collapse
 
michaeljones profile image
Michael Jones

Thanks Ilias! That is much cleaner. A better expression of the intention as well. I'll update our code :)