Created
May 21, 2016 10:48
-
-
Save ivanceras/84e3f71f1f8f57b54e0a9c013904723b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main exposing (..) | |
import Html.App as Html | |
import Html exposing (..) | |
import Json.Decode as Decode exposing (..) | |
type Msg = NoOp | |
type SomePerson = Some Person | |
type alias Person = | |
{first_name: String | |
,last_name: String | |
,parent: SomePerson | |
} | |
type alias Model = | |
{person: Person | |
} | |
person_decoder = | |
object3 Person | |
("first_name" := Decode.string) | |
("last_name" := Decode.string) | |
("parent" := some_person_decoder) | |
some_person_decoder: Decoder SomePerson | |
some_person_decoder = | |
Decode.map Some (person_decoder) | |
john = | |
{first_name = "John" | |
,last_name = "Snow" | |
,parent = Some john | |
} | |
json_person = | |
""" | |
{ | |
"first_name" : "John", | |
"last_name" : "Smith", | |
"parent" : | |
{"first_name" : "John", | |
"last_name": "Snow" | |
} | |
} | |
""" | |
decoded_person: Result String Person | |
decoded_person = | |
decodeString person_decoder json_person | |
default_model = | |
{person= john | |
} | |
init: (Model, Cmd Msg) | |
init = (default_model, Cmd.none) | |
update msg model = | |
(default_model, Cmd.none) | |
view model = | |
pre [] [text (toString model)] | |
main = | |
Html.program | |
{init = init | |
, update = update | |
, view = view | |
, subscriptions = \_ -> Sub.none | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment