Open
Description
The oneOf
decoder stores an Elm list of decoders, but when comparing for equality these lists are compared with _Json_listEquality
, which compares JS arrays. The result is that oneOf
decoders always compare as equal.
I noticed this when a custom event decoder was not being replaced as I expected. Here's an SSCCE that demonstrates such a case.
module Main exposing (main)
import Browser
import Html exposing (Html)
import Html.Events
import Json.Decode
main : Program () Int Int
main =
Browser.sandbox
{ init = 0
, view = view
, update = always
}
view : Int -> Html Int
view clicks =
Html.button
[ Html.Events.on "click"
-- good:
--(Json.Decode.succeed (clicks + 1))
--
-- bad:
(Json.Decode.oneOf [ Json.Decode.succeed (clicks + 1) ])
]
[ Html.text (String.fromInt clicks)
]
Metadata
Metadata
Assignees
Labels
No labels