Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json equality for oneOf decoders always returns true #15

Open
justinmimbs opened this issue Apr 10, 2019 · 2 comments
Open

Json equality for oneOf decoders always returns true #15

justinmimbs opened this issue Apr 10, 2019 · 2 comments

Comments

@justinmimbs
Copy link

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)
        ]
@DavidDTA
Copy link

DavidDTA commented May 8, 2019

This is a duplicate of #13, although this is a good SSCCE!

@rupertlssmith
Copy link

There is a patch for this here: elm/core#905

Which is old enough that it predates the Json stuff being split into a separate package from core.

I commented on it to ask the original author to re-create it on this repo, since it looks like a good patch and still relevant. If the author does not response, I will make a PR out of it on this repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants