One possibility to keep ignored events out of your update and - incidentally - encourage some more reuse, is to move the decision into the decoder:
update
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.
Thanks Ilias! That is much cleaner. A better expression of the intention as well. I'll update our code :)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
One possibility to keep ignored events out of your
update
and - incidentally - encourage some more reuse, is to move the decision into the decoder:The gist is that if an event-decoder fails, the event just happens but no message is sent to Elm.
Thanks Ilias! That is much cleaner. A better expression of the intention as well. I'll update our code :)