Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleaned up static view to match editable view. Added null initializat…
…ion function.
- Loading branch information
Dr. Bearhands
committed
Jan 8, 2018
1 parent
63264c0
commit 2b46a08
Showing
2 changed files
with
54 additions
and
42 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,52 @@ | ||
module Main exposing (main) | ||
|
||
import EditableValue exposing (..) | ||
import EditableValue exposing (EditableValue) | ||
|
||
import Http | ||
import Json.Encode exposing (..) | ||
import Json.Decode exposing (decodeString) | ||
import Html exposing (..) | ||
|
||
type alias Model = | ||
{ editableValue : Maybe EditableValue | ||
{ editableValue : EditableValue | ||
} | ||
|
||
type Msg | ||
= ReceivedJson (Result Http.Error EditableValue) | ||
| SetEditableValue EditableValue | ||
|
||
main : Program Never Model Msg | ||
main : Program Never Model EditableValue | ||
main = Html.program | ||
{ init = init | ||
, view = view | ||
, update = update | ||
, subscriptions = subscriptions | ||
} | ||
|
||
init : (Model, Cmd Msg) | ||
init : (Model, Cmd EditableValue) | ||
init = | ||
let | ||
url = "http://echo.jsontest.com/key/value/otherkey/othervalue" | ||
request = Http.get url decoder | ||
requestAdvertList msg = Http.send msg request | ||
jsonString = "{\"foo\": \"foo\", \"bar\": {\"baz\":[1,2,3,4]}}" | ||
editableValue = | ||
case decodeString EditableValue.decoder jsonString of | ||
Ok editableValue -> editableValue | ||
Err err -> EditableValue.null | ||
in | ||
( { editableValue = Nothing } | ||
, requestAdvertList ReceivedJson | ||
( { editableValue = editableValue } | ||
, Cmd.none | ||
) | ||
|
||
update : Msg -> Model -> (Model, Cmd Msg) | ||
update msg model = | ||
case msg of | ||
ReceivedJson (Ok editableValue) -> ({model | editableValue = Just <| editableValue}, Cmd.none) | ||
ReceivedJson (Err err) -> Debug.crash <| toString err | ||
SetEditableValue newViewer -> ({model | editableValue = Just newViewer}, Cmd.none) | ||
update : EditableValue -> Model -> (Model, Cmd EditableValue) | ||
update newValue model = | ||
({model | editableValue = newValue}, Cmd.none) | ||
|
||
view : Model -> Html Msg | ||
view : Model -> Html EditableValue | ||
view model = | ||
case model.editableValue of | ||
Just editableValue -> | ||
div [] | ||
[ Html.map SetEditableValue (editableView config editableValue) | ||
, br [] [] | ||
, br [] [] | ||
, text <| toString <| encode editableValue | ||
] | ||
Nothing -> div [] [] | ||
|
||
subscriptions : Model -> Sub Msg | ||
let | ||
editableValue = model.editableValue | ||
in | ||
div [] | ||
[ EditableValue.view EditableValue.config editableValue | ||
, br [] [] | ||
, br [] [] | ||
, text <| toString <| EditableValue.encode editableValue | ||
] | ||
|
||
|
||
subscriptions : Model -> Sub EditableValue | ||
subscriptions model = Sub.none |