Last active
October 20, 2016 10:59
-
-
Save chrisbuttery/f3b235293e3dfb75b27242c244853bdc to your computer and use it in GitHub Desktop.
elm-lang equivalent of 2 second SetTimeout.
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 Html exposing (..) | |
import Html.Events exposing (..) | |
import Html.App as App | |
import Task | |
import Process | |
import Time | |
type alias Model = | |
String | |
model : Model | |
model = | |
"not clicked" | |
myTask : Cmd Msg | |
myTask = | |
Task.perform NoOp Foo | |
<| Process.sleep (2 * Time.second) | |
`Task.andThen` \_ -> Task.succeed "not clicked" | |
type Msg | |
= Foo String | |
| Bar | |
| NoOp () | |
update : Msg -> Model -> ( Model, Cmd Msg ) | |
update msg model = | |
case msg of | |
Foo str -> | |
( str, Cmd.none ) | |
Bar -> | |
let | |
txt = | |
if model == "not clicked" then | |
"clicked" | |
else | |
"not clicked" | |
in | |
( txt, myTask ) | |
NoOp _ -> | |
( model, Cmd.none ) | |
view : Model -> Html Msg | |
view model = | |
div [] | |
[ button [ onClick Bar ] [ text "Click" ] | |
, text model | |
] | |
main : Program Never | |
main = | |
App.program | |
{ init = ( model, myTask ) | |
, view = view | |
, update = update | |
, subscriptions = \_ -> Sub.none | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment