From cfca18262c1ff48dcb683ddab7d03cf8e55573ff Mon Sep 17 00:00:00 2001 From: Joris Date: Fri, 24 Mar 2017 09:21:04 +0000 Subject: Features/categories --- src/client/elm/Model/Translations.elm | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'src/client/elm/Model/Translations.elm') diff --git a/src/client/elm/Model/Translations.elm b/src/client/elm/Model/Translations.elm index 57409b0..9b314e1 100644 --- a/src/client/elm/Model/Translations.elm +++ b/src/client/elm/Model/Translations.elm @@ -7,13 +7,13 @@ module Model.Translations exposing ) import Maybe exposing (withDefault) -import Json.Decode as Json exposing ((:=)) +import Json.Decode as Decode exposing (Decoder) import String type alias Translations = List Translation -translationsDecoder : Json.Decoder Translations -translationsDecoder = Json.list translationDecoder +translationsDecoder : Decoder Translations +translationsDecoder = Decode.list translationDecoder type alias Translation = { key : String @@ -27,25 +27,24 @@ getTranslation key translations = |> List.head |> Maybe.map .message -translationDecoder : Json.Decoder Translation +translationDecoder : Decoder Translation translationDecoder = - Json.object2 Translation - ("key" := Json.string) - ("message" := Json.list partDecoder) + Decode.map2 Translation + (Decode.field "key" Decode.string) + (Decode.field "message" (Decode.list partDecoder)) type MessagePart = Order Int | Str String -partDecoder : Json.Decoder MessagePart -partDecoder = - ("tag" := Json.string) `Json.andThen` partDecoderWithTag +partDecoder : Decoder MessagePart +partDecoder = (Decode.field "tag" Decode.string) |> Decode.andThen partDecoderWithTag -partDecoderWithTag : String -> Json.Decoder MessagePart +partDecoderWithTag : String -> Decoder MessagePart partDecoderWithTag tag = case tag of - "Order" -> Json.object1 Order ("contents" := Json.int) - _ -> Json.object1 Str ("contents" := Json.string) + "Order" -> Decode.map Order (Decode.field "contents" Decode.int) + _ -> Decode.map Str (Decode.field "contents" Decode.string) ----- -- cgit v1.2.3