Skip to content

Instantly share code, notes, and snippets.

@chrisbuttery
Last active Oct 20, 2016
Embed
What would you like to do?
elm-lang equivalent of 2 second SetTimeout.
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