Created
June 14, 2016 14:07
-
-
Save lukewestby/d7a9c4e431de3204e77ba974fd6459a2 to your computer and use it in GitHub Desktop.
Elm hardware demo
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 Time | |
import Launchpad exposing (Node, button, group, Color, green, red) | |
type alias Model = | |
{ color : Color } | |
model : Model | |
model = | |
{ color = green } | |
type Msg | |
= ChangeColor | |
update : Msg -> Model -> Model | |
update msg model = | |
let | |
nextColor = | |
if model.color == green then | |
red | |
else | |
green | |
in | |
case msg of | |
ChangeColor -> | |
{ model | color = nextColor } | |
viewButton : Model -> Int -> Node Msg | |
viewButton model row = | |
button model.color True row 0 [] | |
view : Model -> Node Msg | |
view model = | |
group <| List.map (viewButton model) [0..7] | |
subscriptions : Model -> Sub Msg | |
subscriptions model = | |
Time.every 1000 <| always ChangeColor | |
main : Program Never | |
main = | |
Launchpad.program | |
{ view = view | |
, update = \msg model -> ( update msg model, Cmd.none ) | |
, init = ( model, Cmd.none ) | |
, subscriptions = subscriptions | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment