Skip to content

Commit

Permalink
remove unused matchesPlayed field
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHicks committed Sep 15, 2020
1 parent 8bd8c0e commit 0fa336e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 43 deletions.
49 changes: 13 additions & 36 deletions src/League.elm
Expand Up @@ -25,7 +25,6 @@ import Random exposing (Generator)
type League
= League
{ players : Dict String Player
, matchesPlayed : Int
, currentMatch : Maybe Match
}

Expand All @@ -42,46 +41,25 @@ init : League
init =
League
{ players = Dict.empty
, matchesPlayed = 0
, currentMatch = Nothing
}


decoder : Decoder League
decoder =
Decode.oneOf
[ Decode.map2
(\newPlayers matchesPlayed ->
League
{ players = newPlayers
, matchesPlayed = matchesPlayed
, currentMatch = Nothing
}
)
playersDecoder
(Decode.field "matchesPlayed" Decode.int)
, -- old formats
Decode.map
(\newPlayers ->
League
{ players = newPlayers
, matchesPlayed =
newPlayers
|> Dict.values
|> List.map .matches
|> List.maximum
|> Maybe.withDefault 0
, currentMatch = Nothing
}
)
(Decode.oneOf
[ -- old format: : missing matches played
playersDecoder
, -- old format: only players as a dict
Decode.dict Player.decoder
]
)
]
Decode.map
(\newPlayers ->
League
{ players = newPlayers
, currentMatch = Nothing
}
)
(Decode.oneOf
[ playersDecoder
, -- old format: only players as a dict
Decode.dict Player.decoder
]
)


playersDecoder : Decoder (Dict String Player)
Expand All @@ -95,7 +73,6 @@ encode : League -> Encode.Value
encode (League league) =
Encode.object
[ ( "players", Encode.list Player.encode (Dict.values league.players) )
, ( "matchesPlayed", Encode.int league.matchesPlayed )
]


Expand Down
7 changes: 0 additions & 7 deletions tests/LeagueTest.elm
Expand Up @@ -36,13 +36,6 @@ decoderTests =
League.encode league
|> Decode.decodeValue League.decoder
|> Expect.equal (Ok league)
, fuzz leagueFuzzer "is backwards-compatible with the missing matches-played format" <|
\league ->
Encode.object [ ( "players", Encode.list Player.encode (League.players league) ) ]
|> Decode.decodeValue League.decoder
-- matches played will change with this. That's fine.
|> Result.map League.players
|> Expect.equal (Ok (League.players league))
, fuzz leagueFuzzer "is backwards-compatible with the older dictionary format" <|
\league ->
League.players league
Expand Down

0 comments on commit 0fa336e

Please sign in to comment.