Created
December 11, 2015 02:59
-
-
Save iammerrick/7f687cdc978c1b8e2aba to your computer and use it in GitHub Desktop.
This is bad elm code I wrote.
This file contains hidden or 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
import StartApp.Simple as StartApp | |
import Html exposing (..) | |
import Html.Attributes exposing (..) | |
import Html.Events exposing (..) | |
import Signal exposing (Address) | |
import Json.Decode as Json | |
main = | |
StartApp.start { model = model, view = view, update = update } | |
model = | |
{ | |
naughtyField = "", | |
niceField = "", | |
naughty = ["Joe"], | |
nice = ["Merrick"] | |
} | |
person item = | |
div [] | |
[text item] | |
people list = | |
div [] | |
(List.map person list) | |
xmaslist address field list title action updateAction = | |
div [] | |
[ h1 [] [text title] | |
, input | |
[ | |
type' "text" | |
, value field | |
, onEnter address action field | |
, onInput address updateAction | |
] [] | |
, people list | |
] | |
onEnter address value field = | |
on "keydown" | |
(Json.customDecoder keyCode is13) | |
(\_ -> Signal.message address (value field)) | |
onInput address value = | |
on "input" targetValue (\str -> Signal.message address (value str)) | |
is13 code = | |
if code == 13 then Ok () else Err "not the right key code" | |
view address model = | |
div [] | |
[xmaslist address model.naughtyField model.naughty "Naughty" AddToNaughty UpdateNaughtyField, xmaslist address model.niceField model.nice "Nice" AddToNice UpdateNiceField] | |
type Action | |
= AddToNaughty String | |
| AddToNice String | |
| UpdateNiceField String | |
| UpdateNaughtyField String | |
update action model = | |
case action of | |
AddToNice name -> | |
{ model | | |
niceField = "", | |
nice = model.nice ++ [name] | |
} | |
AddToNaughty name -> | |
{ model | | |
naughtyField = "", | |
naughty = model.naughty ++ [name] | |
} | |
UpdateNiceField name -> | |
{ model | | |
niceField = name | |
} | |
UpdateNaughtyField name -> | |
{ | |
model | | |
naughtyField = name | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment