Created
August 20, 2016 05:50
-
-
Save justinmimbs/fa580fabd39ba4e3f53d84dd5357863c 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
import Html exposing (Html, div, h1, br, button, text) | |
import Html.App as App | |
import Html.Events exposing (onClick) | |
import Html.Attributes exposing (style) | |
import VirtualDom as Dom | |
import String | |
main = | |
App.beginnerProgram | |
{ model = list1 | |
, update = update | |
, view = view | |
} | |
list1 = [ 1, 2, 3, 4, 5 ] | |
list2 = [ 3, 2, 5, 4, 1 ] | |
update : Int -> List Int -> List Int | |
update listNumber _ = | |
case listNumber of | |
1 -> list1 | |
_ -> list2 | |
view : List Int -> Html Int | |
view list = | |
div [] | |
[ div [ styleColumn ] | |
[ text "node" | |
, Dom.node | |
"ul" [] (list |> List.map viewItem) | |
] | |
, div [ styleColumn ] | |
[ text "keyedNode" | |
, Dom.keyedNode | |
"ul" [] (list |> List.map viewKeyedItem) | |
] | |
, div [ style [ ("clear", "both") ] ] [] | |
, button [ onClick 1 ] [ text <| String.join " " (List.map toString list1) ] | |
, br [] [] | |
, button [ onClick 2 ] [ text <| String.join " " (List.map toString list2) ] | |
] | |
styleColumn : Html.Attribute a | |
styleColumn = | |
style | |
[ ("float", "left") | |
, ("margin-right", "1em") | |
] | |
viewItem : Int -> Dom.Node a | |
viewItem n = | |
Dom.node "li" [] [ Dom.text (toString n) ] | |
viewKeyedItem : Int -> (String, Dom.Node a) | |
viewKeyedItem n = | |
(toString n, viewItem n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment