aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/Model/InitResult.elm
diff options
context:
space:
mode:
authorJoris2016-03-31 00:06:50 +0200
committerJoris2016-03-31 00:13:25 +0200
commitc95e19407d492a0d4e9e14e320520fe29ce379e5 (patch)
treeca6a14ad1396af6a4bc36e17ce89278d5dbea0a0 /src/client/elm/Model/InitResult.elm
parentc542551ad043260e6a4a6569b4af5c748f7b6001 (diff)
downloadbudget-c95e19407d492a0d4e9e14e320520fe29ce379e5.tar.gz
budget-c95e19407d492a0d4e9e14e320520fe29ce379e5.tar.bz2
budget-c95e19407d492a0d4e9e14e320520fe29ce379e5.zip
Add init data in html page
Diffstat (limited to 'src/client/elm/Model/InitResult.elm')
-rw-r--r--src/client/elm/Model/InitResult.elm28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/client/elm/Model/InitResult.elm b/src/client/elm/Model/InitResult.elm
new file mode 100644
index 0000000..d1f1348
--- /dev/null
+++ b/src/client/elm/Model/InitResult.elm
@@ -0,0 +1,28 @@
+module Model.InitResult
+ ( InitResult(..)
+ , initResultDecoder
+ ) where
+
+import Json.Decode as Json exposing ((:=))
+
+import Model.Init exposing (Init, initDecoder)
+
+type InitResult =
+ InitEmpty
+ | InitSuccess Init
+ | InitError String
+
+initResultDecoder : Json.Decoder InitResult
+initResultDecoder = ("tag" := Json.string) `Json.andThen` initResultDecoderWithTag
+
+initResultDecoderWithTag : String -> Json.Decoder InitResult
+initResultDecoderWithTag tag =
+ case tag of
+ "InitEmpty" ->
+ Json.succeed InitEmpty
+ "InitSuccess" ->
+ Json.map InitSuccess ("contents" := initDecoder)
+ "InitError" ->
+ Json.map InitError ("contents" := Json.string)
+ _ ->
+ Json.fail <| "got " ++ tag ++ " for InitResult"